【发布时间】:2016-09-24 14:42:29
【问题描述】:
嘿,我从我的ItemsController 访问@interestedusers = User.itemfavorites.where(item_id: @item.id) 时遇到问题:
NoMethodError in ItemsController#show
undefined method `itemfavorites' for #<Class:0xfb94bb8>
路线
resources :items do
get :itemfavorites, on: :member
end
用户模型
# Favorite items of user
has_many :favorite_items # just the 'relationships'
has_many :itemfavorites, through: :favorite_item, source: :item # the actual items the user favorites
物品模型
# Favorited by users
has_many :favorite_items # just the 'relationships'
has_many :itemsfavorited_by, through: :favorite_items, source: :user # the actual users favoriting an item
一般关联有效,我对其进行了测试,我可以添加/删除和显示收藏夹。
我正在尝试显示用户收藏的项目。
提前感谢每个答案!如果您需要更多信息,请告诉我。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 associations nomethoderror