I am using 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 am having problem in setting up dynamic nested person form where the user can add many addresses inside a form and save all of them at once. My hash while updating the person nested form is like 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"=&开发者_StackOverflowgt;"2010-11-10", "end_date"=>""}
But the address doesn't get updated according the hash recieved.
Any idea why this is happening?
Thanks
Try adding accepted_nested_attributes_for to your Person model
精彩评论