0
나는 레일에서 세 개의 클래스가있는 경우 :Has_many 레일 협회 => NoMethodError
class Item::Part::Element < ActiveRecord::Base
belongs_to :item_part, :foreign_key => 'item_part_id'
self.table_name = 'item_part_elements'
end
class Item::Part < ActiveRecord::Base
has_many :elements
belongs_to :item, :foreign_key => 'item_id'
self.table_name = 'item_parts'
end
class Item < ActiveRecord::Base
has_many :parts
self.table_name = 'item'
end
와 나는
@item.parts
가 잘 작동하지만 내가 전화를
@item_part.elements
다음 한 경우를 호출하는 경우
은 오류를 throw합니다.
NoMethodError: undefined method "elements"
연결이 잘못되었거나 다른 문제가 있습니까?
모든 세부 사항을 모른 채 말하기는 어렵습니다. 인스턴스 변수를 어떻게 인스턴스화합니까? 또한'NoMethodError',하지만 무엇을 위해서? 'nil'을 위해서? – blelump
NoMethodError : Item :: Part – bootsa
에 대한 정의되지 않은 메서드 "elements"는 'item_part_id'및 'item_id'를 사용할 때'self'가 암시합니까? – pdoherty926