请问有人可以解释如何在rails中动态添加表单的另一个副本吗?...已经工作了近2小时。我在jquery中乱用.clone()和.appendTo,但它没有用。此外,我在网上找到的大多数材料(如railscast#196和stackoverflow)都非常关注嵌套表格。我的表单是嵌套的,但实际上我只是想再次添加父表单。嵌套的照片使用html多个属性,所以我猜这将为每个父表单处理多个文件上传(顺便说一句,我正在使用paperclip)。
如果我只需要修改railscast代码,请告诉我。
感谢。
<%= form_for(@user_book, html: { multipart: true }) do |f| %>
<% if @user_book.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user_book.errors.count, "error") %> prohibited this user_book from been saved:</h2>
<ul>
<% @user_book.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<p>hello</p>
<% end %>
</ul>
</div>
<% end %>
<%= f.text_field :title, placeholder: "enter title...", id: "book_title" %>
<%= f.text_field :category, placeholder: "enter category..." %>
<%= file_field_tag 'user_book[user_book_photos_attributes][][photo]', :multiple => true do |p| %>
<%= p.file_field :photo %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>