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