开发者

how add two and more nested forms with mongoid

开发者 https://www.devze.com 2023-03-08 07:33 出处:网络
i use mongoid in rails3 app. I have two documents: companies, company_addresses. Company embeds_many company_addresses.

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| %>
0

精彩评论

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