开发者

embeds many nested form, mongoid

开发者 https://www.devze.com 2023-01-30 22:11 出处:网络
I am using mongoid as my database. And my model is like this class Address include Mongoid::Document embedded_in :person, :inverse_of => :addresses

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

0

精彩评论

暂无评论...
验证码 换一张
取 消