0
@item.associations.update_attributes(:tag_id=>params[:tag])
和
@item.associations.tag_id=params[:tag]
兩個分別給我update_attributes方法未定義的方法錯誤和TAG_ID =。這是我的設置:
class Item < ActiveRecord::Base
has_many :associations,:foreign_key=>"item_id",:dependent=>:destroy
has_many :reverse_associations,:foreign_key=>"tag_id",:class_name=>"Association"
has_many :tags,:through=>:associations
end
class Tag < ActiveRecord::Base
has_many :associations,:foreign_key=>"tag_id",:dependent=>:destroy
has_many :reverse_associations,:foreign_key=>"item_id",:class_name=>"Association"
has_many :items,:through=>:associations
attr_accessible :name
end
class Association < ActiveRecord::Base
belongs_to :item
belongs_to :tag
end
我在做什麼錯?
哦。 「咄」那一刻,我...現在只有一個該項目的關聯,所以我想這並沒有發生在我身上。 – herpderp 2010-10-26 09:03:13
當然,現在我才意識到,更新關聯甚至沒有必要,我可以只創建/根據需要摧毀。 – herpderp 2010-10-26 09:15:52