Thursday 15 September 2011

forms - rails 3 mass assignment error, simple yet unresolvable -


I'm trying to figure out why I get public-assignment errors when my code looks correct I am Am I using the wrong syntax? I really appreciate any beta, I am trying to debug such a simple part of my application and really stopping my progress. I have the following:

controller
  class product controller & lt; ApplicationController def new @product = Product.new def @product = Product.new ([: product] parameter) to create end-to-end other end   

Model
  Class products & lt; ActiveRecord :: Base attr_accessible: name ,: colors_attributes has_many: colors accepts_nested_attributes_for: colors, allow_destroy: true end class color & lt; ActiveRecord :: Base attr_accessible: name ,: product_id belongs_to: product end   

migration
  class CreateProducts & lt; ActiveRecord :: migrations deff changes make_table: products do | T | T.string: Name t.timestamps End End and Class CreateColors & lt; ActiveRecord :: Migration Def Change make_table: colors do | T | T.integer: product_id t.string: name t.timestamps end and end   

view

products / new.html.erb

 < Code> & lt;% = Render "form"%>   

Products / _form.html. ARB

  & lt;% = form_for @product do | F | & Gt%; & Lt;% = f.text_field: name% & gt; & Lt;% = f.fields_for: Color | C | & Gt%; & Lt;% = Render 'color_fields', f: c% & gt; & Lt;% end% & gt; & Lt;% = f.button: Submit% & gt; & Lt;% end% & gt;   

Products / _color_fields.html.erb

  & lt;% = f.text_field: name% & gt;   

Error:

  ActiveModel :: MassAssignmentSecurity :: error to ProductsController # to make can protect property extensively assign color < / code>  

full trace:

  activemodel (3.2.3) lib / active_model / mass_assignment_security / sanitizer.rb: 48: `process_removed_attributes' activemodel in (3.2 .3) lib / active_model / mass_assignment_security / sanitizer.rb: 20: in `debug_protected_attribute_removal 'activemodel (3.2.3) lib / active_model / mass_assignment_security / sanitizer.rb: 12: Men` clean' activemodel (3.2.3) lib / active_model / mass_assignment_security.rb: 230: `sanitize_for_mass_assignment in 'ActiveRecord (3.2.3) lib / active_record / attribute_assignment.rb: 75:` assig 'ActiveRecord (3.2.3) lib / active_record / base.rb: 498 in n_attributes:' In Startup App / Controller / Products_controller RB: 7: `new 'app / controller / product_controller RB: 7: 'Action' Action Pack in (3.2.3) lib / action_controller / metal / implicit_render.rb: 4: `Akshn_akshn 'Action Pack (3.2.3) lib / abstract_c Ontroller / base.rb: 167:` In process_action '...   

Any insights will be appreciated

< P> I believe this is what you need
  & lt;% = form_for @product do | F | & Gt%; & Lt;% = f.text_field: name% & gt; & Lt;% = f.fields_for: Color | C | & Gt%; & Lt;% = Render 'color_fields', f: c% & gt; & Lt;% end% & gt; & Lt;% = f.button: Submit% & gt; & Lt;% end% & gt;   

was using instead of your fields_for : color : color

No comments:

Post a Comment