简体   繁体   English

Formtastic。 如何为同一模型的多个对象创建表单?

[英]Formtastic. How to create a form for multiple objects of the same model?

I have a subject model with two fields - "name" and "level". 我有一个带有两个字段的主题模型-“名称”和“级别”。 I want to be able to visit "/subjects#new" and add 10 subjects objects at once. 我希望能够访问“ / subjects#new”并一次添加10个对象对象。 How can I do this in formtastic. 我该怎么做呢?

In regular forms I would do this: 我将以常规形式执行以下操作:

<% @subjects.each do |s| %> 
   <% fields_for "subject[#{s.id}]", s do |f|%>                                                                  
     <%= f.name%>
     <%= f.level %>
   <% end %> 
<% end %>   

将fields_for更改为semantic_fields_for,它将正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM