简体   繁体   中英

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. 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,它将正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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