我有三種模式:用戶,指南和favourite_guideline(目的是讓用戶可以創建自己喜歡的指南列表)。在 模型收藏:has_many:通過關聯錯誤'找不到源協會'
我越來越想添加收藏夾
的ActiveRecord :: HasManyThroughSourceAssociationNotFoundError在 GuidelinesController#喜愛 找不到源協會(S)當一個關聯錯誤:最喜歡的還是FavouriteGuideline。試試'has_many:favorites,:through => :favourite_guidelines,:source =>'。它是以下之一:指南還是 :用戶?在指導方針控制器
類用戶<的ActiveRecord :: Base的
has_many :guidelines
has_many :favourite_guidelines
has_many :favourites, through: :favourite_guidelines
end
class Guideline < ActiveRecord::Base
belongs_to :user
has_many :favourite_recipes
has_many :favourited_by, through: :favourite_recipes, source: :user
end
class FavouriteGuideline < ActiveRecord::Base
belongs_to :guideline
belongs_to :user
end
我的收藏操作是:
def favourite
type = params[:type]
if type == "favourite"
current_user.favourites << @guideline
redirect_to :back, notice: 'You favourited #{@guideline.name}'
elsif type == "unfavourite"
current_user.favourites.delete(@guideline)
redirect_to :back, notice: 'Unfavourited #{@guideline.name}'
else
# Type missing, nothing happens
redirect_to :back, notice: 'Nothing happened.'
end
end
感謝 - 這仍是給予同樣的錯誤消息。我注意到錯誤標題是'GuidelinesReceiver :: HasManyThroughSourceAssociationNotFoundError在GuidelinesController#最喜歡' - 我已經將最喜歡的動作複製到我的問題上面,以防萬一它是一個問題... – tessad 2013-02-13 06:39:20