Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't mass-assign protected attributes: _destroy - Ruby on Rails
    primarykey
    data
    text
    <p>I'm getting this error:</p> <p>"ActiveModel::MassAssignmentSecurity::Error in DaysController#create</p> <p>Can't mass-assign protected attributes: _destroy"</p> <p>I didn't even know that _destroy is an attribute!</p> <p>What I have going on:</p> <p>My model is that I have "Trips" which has many "Days"</p> <p>In the "Show" view of my Trips model, I'm rendering a partial for a Form to add a new "Day":</p> <pre><code>&lt;div id="day_form"&gt; &lt;%= render :partial =&gt; "day_form", :day =&gt; @day %&gt; &lt;/div&gt; </code></pre> <p>My model:</p> <pre><code>class Trip &lt; ActiveRecord::Base attr_accessible :title, :days_attributes has_many :days accepts_nested_attributes_for :days, allow_destroy: true end class Day &lt; ActiveRecord::Base attr_accessible :activity_id, :order, :summary, :trip_id, :activities_attributes belongs_to :trip has_many :activities, :order =&gt; 'position' accepts_nested_attributes_for :activities, allow_destroy: true end </code></pre> <p>When I submit the form, I am getting this Mass Assignment error. Why?</p> <p><strong>EDIT</strong></p> <p>The 'Day' Form looks like this:</p> <pre><code> &lt;%= form_for(@day) do |f| %&gt; &lt;ul&gt; &lt;% @day.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;fieldset&gt; &lt;%= f.label :summary, "Day Summary" %&gt;&lt;br /&gt; &lt;%= f.text_area :summary, :rows =&gt; 1 %&gt;&lt;br /&gt; &lt;%= f.hidden_field :_destroy %&gt; &lt;%= link_to "remove", '#', class: "remove_fields" %&gt; &lt;/fieldset&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload