我通过与我的模型相关联来设置has_many,并且我试图创建一个表单,可以将多个流派添加到提交的歌曲中。我为此使用了collection_select助手。这里是我的代码是如何设置的片段。通过使用Rails通过has_many保存collection_select
宋型号
has_many :song_genres
has_many :genres, :through => :song_genres
类型型号
has_many :song_genres
has_many :songs, :through => :song_genres
歌曲种类型号
belongs_to :song
belongs_to :genre
然后在我的new.html.erb 我有这个
collection_select :song, :genres, Genre.all, :id, :name, {:selected => 1}, {:multiple => true}
当我提交表单,我收到了
Can't mass-assign protected attributes: genres
错误
我知道我失去了一些东西大在这里。有人可以帮我解决这个问题吗?
谢谢!
完整的解决方案在评论中。 – Dan 2012-03-21 01:24:05