Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Form, "Can't mass-assign protected attributes"

This is the relevant part of my nested form:

<div class="field">
<%= f.fields_for "@partcode" do |p|%> 

  <%= p.label "partcode"%><br />
  <%= p.text_field :partcode %>

<% end %>
</div>

and i already have this in my model:

attr_accessible :partcode,
                :description

yet when i enter something in to the form, i get this error:

Can't mass-assign protected attributes: @partcode

Here is my partcode model:

class Partcode < ActiveRecord::Base
 attr_accessible :partcode,
              :description

  validates       :partcode,
              :description,
              :presence => true

 belongs_to "goods_ins"

 accepts_nested_attributes_for "goods_ins"


end

and here is all the code from my goods in model:

class GoodsIn < ActiveRecord::Base
  attr_accessible :c4lpono, 
              :courier, 
              :deliverydate,  
              :deliverynoteno,  
              :description,  
              :destination,  
              :notes,  
              :partcode,  
              :quantity,  
              :signedby,  
              :suppliername

  validates       :deliverydate,  
              :deliverynoteno,  

              :destination,

              :quantity,  
              :signedby,  
              :suppliername,
              :presence => true

 has_many :suppliers

 has_many :partcodes

 accepts_nested_attributes_for :partcodes
end

Also here is the new part of my partcode controller:

def new
@partcode = Partcode.new

respond_to do |format|
  format.html # new.html.erb
  format.json { render :json => @partcode }
end
end 
like image 656
Carla Dessi Avatar asked Dec 11 '25 09:12

Carla Dessi


1 Answers

Should'nt you have :partcode_attributes to attr_accessible(in GoodsIn Model), like this:

attr_accessible :partcode_attributes

Assuming your model association is configured that way. hope it helps

like image 83
Hishalv Avatar answered Dec 12 '25 21:12

Hishalv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!