app/services
에는 Notification::Finder
및 Notification::Builder
과 같은 몇 가지 클래스가 있습니다.autoload_paths는 네임 스페이스를 인식하지 못합니까?
이들은 각각 app/services/notification/builder.rb
및 app/services/notification/finder.rb
입니다. 내가 Finder
를로드 할 때 app/models/notification.rb
autoload_path에서 모델로 Notification
클래스도 있습니다
이 config.autoload_paths += %W(#{config.root}/app/services)
같이 컨피그, 그것은 작동 :
Loading development environment (Rails 3.2.9)
[1] pry(main)> Notification::Finder
=> Notification::Finder
그러나 때 을 시도하면 레일 로딩에 문제가 발생합니다.
Loading development environment (Rails 3.2.9)
[1] pry(main)> Notification::Builder
=> ActiveRecord::Associations::Builder
상수 이름 (작성자)이 이미 다른 네임 스페이스에서 정의되었을 때 사용했던 네임 스페이스를 무시하고 대신 ActiveRecord::Associations::Builder
을 가져옵니다.
예상되는 동작입니까, 레일 버그입니까? 상세한가는
, activesupport/dependencies.rb
에서 const_missing
방법은 const_name 'Builder'
및 nesting.inspect => 'nil'
를 수신한다.
호기심 내가 constantize를 사용하는 경우, 그것은 예상대로 해결하는 것이 :
Loading development environment (Rails 3.2.9)
[1] pry(main)> 'Notification::Builder'.constantize
=> Notification::Builder
(레일 문제를 GitHub의에서 : https://github.com/rails/rails/issues/8726)
'Builder'가 예약 된 이름 일 수 있습니까? – tadman
@ tadman 아니에요/ –
신선한 응용 프로그램에서 재현 할 수 있습니까? 그렇다면 github에 올려 놓고 알려주세요. 내가 한번 볼게. 레일 오토로더가 올바른 결과를 반환 할 수없는 경우가 있습니다. 나는 이것이 가능해야한다고 생각한다. –