Note that there are some explanatory texts on larger screens.

plurals
  1. POnested form "Can't mass-assign protected attributes"
    primarykey
    data
    text
    <p>I have 3 models; Quote, Item, and Product.</p> <p>My quote/new.html.erb is set up to render a partial which contains the item form, and in that item form a partial is rendered to choose a product.</p> <p>the error: ActiveModel::MassAssignmentSecurity::Error in QuotesController#create "Can't mass-assign protected attributes: products"</p> <p>(I edited out irrelevant stuff in the following) Quote.rb</p> <pre><code>class Quote &lt; ActiveRecord::Base attr_accessible :items_attributes has_many :items, :dependent =&gt; :destroy accepts_nested_attributes_for :items end </code></pre> <p>Item.rb</p> <pre><code>class Item &lt; ActiveRecord::Base attr_accessible :price, :product_attributes belongs_to :quote belongs_to :product accepts_nested_attributes_for :product end </code></pre> <p>Product.rb</p> <pre><code>class Product &lt; ActiveRecord::Base attr_accessible :name, :item_make has_many :items accepts_nested_attributes_for :items end </code></pre> <p>new.html.erb</p> <pre><code>&lt;%= simple_nested_form_for @quote do |m| %&gt; &lt;%= m.simple_fields_for :items, :html =&gt; { :multipart =&gt; true } do |quoteform| %&gt; &lt;%= render "form", f: quoteform %&gt; &lt;% end %&gt; &lt;%= m.link_to_add "Add an item", :items %&gt; &lt;%= m.button :submit %&gt; &lt;% end %&gt; </code></pre> <p>_form.html.erb</p> <pre><code>&lt;%= f.simple_fields_for :products, :html =&gt; { :multipart =&gt; true } do |x| %&gt; &lt;% render "layouts/styleselect", g: x %&gt; &lt;% end %&gt; </code></pre> <p>_styleselect.html.erb</p> <pre><code>&lt;% g.hidden_field :item_make, :value =&gt; @item.make %&gt; &lt;%= g.input :name, collection: Product.where(:item_make =&gt; 1), label: false, input_html: {:id=&gt;"sst_style"} %&gt; </code></pre> <p>So basically the nested form goes Quote->Item->Product, but item belongs to product, which maybe is causing the problem? I tried adding product_attributes or products_attributes to both the item model and the quote model, and the same with accepts_nested_attributes_for product(s). </p> <p>Any help would be appreciated, thanks.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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