私のモデルとの関連付けによって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