how add two and more nested forms with mongoid
i use mongoid in rails3 app. I have two documents: companies
, company_addresses
.
Company embeds_many company_addresses.
And after i create form for Company and nested Company_o开发者_开发问答ffices:
<%= form_for @company do |f| %>
.....
.....<%= render :partial => 'company_offices/form', :locals => { :build => f, :company => @company } %>
<% end %>
Nested form is:
<%= build.fields_for company.company_offices.build do |f| %>
..........
<% end %>
But i want in one request add two addresses for company, and if i do:
<%= form_for @company do |f| %>
.....
.....<%= render :partial => 'company_offices/form', :locals => { :build => f, :company => @company } %>
<%= render :partial => 'company_offices/form', :locals => { :build => f, :company => @company } %>
<% end %>
It sends only last company_address, what i do bad?
replace
<%= build.fields_for company.company_offices.build do |f| %>
with
<%= 2.times { company.company_offices.build } %>
<%= build.fields_for :company_offices do |f| %>
精彩评论