0

現時点では、ネストされたフォームを使用して、曲を作成するときにカテゴリ タグを曲に追加しようとしています。現時点では、正しい属性のアクセス可能な特性であると信じているものを入力したにもかかわらず、フォームを送信するたびに大量割り当てエラーがスローされます。明らかに私はどこかで間違っているので、誰かが私のためにそれを指摘できれば素晴らしいと思います. フォームは次のとおりです。

<%= nested_form_for(@song) do |f| %>
         ...
      <%= f.fields_for(@song.categorizations.build) do |cat| %>
        <%= cat.label :category_id, "TAG" %>
        <%= cat.select :category_id, options_for_select(Category.all.collect {|c| [ c.tag, c.id ] }, 
        { :include_blank => true }), prompt: "" %>
      <%end%>
      <%= f.submit "Save" %>
    <% end %>

関連するモデルは次のとおりです。

class Song < ActiveRecord::Base
  attr_accessible :artist, :title, :categorizations_attributes
  has_many :categorizations, dependent: :destroy
  has_many :categories, through: :categorizations

  accepts_nested_attributes_for :categorizations

ソングコントローラーは次のようになります。

 def create
    @song = Song.new(params[:song])
    if @song.save
        flash[:success] = "Song successfully added to library"
        redirect_to @song
    else
        #FAIL!
        render 'new'
    end
  end

最後に発生するエラーは次のとおりです。

ActiveModel::MassAssignmentSecurity::Error in SongsController#create

Can't mass-assign protected attributes: categorization

助けてくれてありがとう!

4

0 に答える 0