으로 표시하면 상자 컨트롤러 또는 뷰 내에 item_category.name 특성을 표시하는 올바른 방법은 무엇입니까?아래 예제에서 상위에서 하위로 상위 모델의 특성을
class Box < ActiveRecord::Base
has_one :item, :dependent => :destroy
accepts_nested_attributes_for :item, :allow_destroy => true
end
class Item < ActiveRecord::Base
belongs_to :box
belongs_to :item_category
end
class ItemCategory < ActiveRecord::Base
has_many :items
#contains 'name' attribute
end
나는 일 나던있는이 같은 일부 구문이 기대 오전 :
<%= @box.item.item_category.name %>
이 "무기 호에 대한 정의되지 않은 메서드`이름 'NilClass를"나에게 다음과 같은 오류를 제공
감사
가EDIT : 죄송합니다. 항목 클래스에 belongs_to item_category (회사가 아닌)가 포함되어 있으므로 샘플을 편집했습니다.
컨트롤러에 코드를 게시하십시오. – PhillipKregg