Implements many nested forms, mangoids

I use mongoid as my database.

And my model is like this

class Address
  include Mongoid::Document
  embedded_in :person, :inverse_of => :addresses
end

class Person
  include Mongoid::Document
  embeds_many :addresses
end

I had a problem with setting up a dynamic nested user form, when the user can add many addresses inside the form and save everything at once. My hash when updating a person’s nested form is similar to this

"person"=>{"name"=>"John", 
"addresses_attributes"=>{"0"=>{"address1"=>"calgary","address2"=>"New York", "id"=>"4cef79f67adf3509280001be"}, 
                         "1"=>{"address1"=>"bhah", "address2"=>"blah", "id"=>"4cef74rdeadf3509280001bf"}}, 
"policy_id"=>"4cef5feb7adf35092800013a", 
"start_date"=>"2010-11-10", "end_date"=>""}

But the address is not updated in accordance with the received hash.

Any idea why this is happening?

thank

+5
source share
1 answer

Try adding accept_nested_attributes_for to your Person model

0
source

All Articles