如何使用 mongoid 添加两个或更多嵌套形式
我在rails3应用程序中使用mongoid。我有两个文档:companies
、company_addresses
。 公司嵌入_许多公司_地址。
在我为公司和嵌套的 Company_offices 创建表单后:
<%= form_for @company do |f| %>
.....
.....<%= render :partial => 'company_offices/form', :locals => { :build => f, :company => @company } %>
<% end %>
嵌套表单是:
<%= build.fields_for company.company_offices.build do |f| %>
..........
<% end %>
但我想在一个请求中为公司添加两个地址,如果我这样做:
<%= 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 %>
它只发送最后一个 company_address,我做错了什么?
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_offices:
<%= 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
替换
为
replace
with