가 여기 내 클래스 계층 구조의 레일에 제대로로드되지 다음추상 클래스가
class Item < ActiveRecord::Base
TYPES = [Weapon::TYPES, Armour::TYPES, Misc::TYPES].flatten.freeze
end
과, 추상 클래스는 중입니다 양식 :
class Misc < Item
self.abstract_class = true
TYPES = G_BASE_NAMES["misc"].keys.freeze
end
콘솔을 시작하면 다음과 같은 메시지가 표시됩니다.
/Users/hello_so/localhost/search/app/models/item.rb:7:in '': 초기화되지 않은 일정 항목 :: 기타
항목에서 7 호선. rb는 TYPES = ...
행입니다.
왜 무기 및 갑옷이 아닌 기타에 대해 불만을 나타내나요? (파일 btw에서 처음 나타나는)?
편집 : 나는 실제로 내가 그것을 제거하면, 나는 콘솔을 실행할 수 있습니다
if Rails.env.development?
Dir[Rails.root + 'app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
end
(문제를 해결하려고 최근에 내가 추가 뭔가를) 이니셜 라이저에서 그 일을했다.
또 다른 이상한 것은 :
$ rails c
> WEAPON
> NameError: uninitialized constant Weapon #why is it looking for the class??
> from /Users/hello_so/localhost/search/app/models/item.rb:7:in `<class:Item>'
하지만 (Item
을 입력하여) Item
를로드하는 경우, 다음은 무기 상수에 대해 불평한다.
여기서 '기타'가 정의되어 있습니까? ':: Misc :: TYPES'을하면 어떻게 될까요? – apneadiving
기타는 모델/misc.rb에 있으며 무기 및 갑옷과 완전히 동일합니다. 나는 노력했다 :: 잡다한. – Robin
모델에있는 경우 기타 일뿐입니다. misc.rb가 아닌 Item :: Misc. – Intelekshual