ruby on rails - nested form & update_attributes -


i having trouble updating data in multi-level nested form. use partials include fields both create & update views, , not have problem creating. updating.

essentially structure (simplified) is:

user has_one profile profile has_many addresses  form_for @user |u|   u.fields_for :profile |p|     p.fields_for :addresses |a| 

like said, creating user, profile, , addresses works fine. until attempt update find problems. don't receive error, shows updated. , update user & profile fields, not address fields.

here params update stack trace. (again, summarized & formatted)

parameters: {"controller"=>"profiles", "action"=>"update", "_method"=>"put", "id"=>"1",    "user"=>{"login" => "username",     "profile_attributes"=>{"first_name"=>"admin",       "addresses_attributes"=>{         "0"=>{"address"=>"123 address ave.", "city"=>"cityville", "state"=>"ca"}       }     }   } } 

all of documentation can find shows 1 nested form, not sure if using update_attributes more 1 level deep.

any thoughts?

are using attr_accessible anywhere in model, whitelist fields allowed mass assignment? if so, you'll also need add

attr_accessible :address_attributes 

to allow attributes passed update_attributes.

if aren't using attr_accessible (or it's not-recommended sister attr_protected) don't add line it'll stop of ther attributes being saved.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -