0
這裏是我的相關機型:訪問軌道屬性通過深協會
class ListItem < ActiveRecord::Base
belongs_to :inventory_item
belongs_to :shopping_list
belongs_to :item
end
class ShoppingList < ActiveRecord::Base
has_many :list_items
belongs_to :user, :foreign_key => :user_id
end
class InventoryItem < ActiveRecord::Base
belongs_to :item, :foreign_key => :item_id
belongs_to :vendor
has_many :list_items
end
我試圖訪問在我看來InventoryItem的屬性。這是我目前在我的ShoppingListController
中所擁有的。
def show
@list_items = ShoppingList.find(params[:id]).list_items
end
我可以做點像@inventory_items = @list_items.inventory_items
嗎?我試過的那些代碼和變體沒有奏效。我在這裏錯過了什麼?通過這樣的多個模型訪問屬性的任何提示?提前致謝!
它說明了什麼錯誤? –