简体   繁体   English

Rails-Simple_fields_for不提交多个记录

[英]Rails - Simple_fields_for not submitting multiple records

I'm trying to create a form that allows a user to select different choices for each category on the same form, and each of these will create its own model. 我正在尝试创建一个表单,该表单允许用户为同一表单上的每个类别选择不同的选项,并且每个选项都会创建自己的模型。 My problem is getting the form to submit multiple parameters. 我的问题是让表单提交多个参数。 My code is as follows: 我的代码如下:

      <%= simple_form_for choices_path do |f| %>
        <td><%= person.fullname %></td> 
        <td><%= person.email %></td> 
        <td><%= person.phone %></td> 
        <% if Category.any? %>
          <%= f.simple_fields_for :choices do |g| %>
            <% Category.all.each do |category| %>
              <td>
                <%= g.input :item_id, as: :select, collection: booking.venue.menu_items(category) %>
                <%= g.hidden_field :admin_id, value: person.id %>
              </td>
            <% end %>
          <% end %>
        <% end %>
        <td><%= person.completed? %></td>
        <td><%= f.submit %></td>
      <% end %>

The idea obviously being to create a new form for each category. 这个想法显然是为每个类别创建一个新表格。 This works until submitting the data, where only the last form's data is submitted. 直到提交数据(仅提交最后一个表单的数据)之前,此方法一直有效。 My paramaters are as follows: 我的参数如下:

{"utf8"=>"✓", "authenticity_token"=>"tf3DSLGHyOVEVJkcLjSVE9HDJbjn1CIaYBJIfHFw6RYH8tcn0tNilWVIjzyvcjXYm2ovKNO5A31+TktGA8X2+Q==",
 "/choices"=>{"choices"=>{"item_id"=>"Dessert 1", "admin_id"=>"3"}},
 "commit"=>"Save /choices",
 "venue_id"=>"1",
 "booking_id"=>"26"}

I can see that its creating a hash and is ready to submit multiple choices, however it is only the last record's data that is submitted. 我可以看到它创建了一个散列并准备提交多个选择,但是仅提交了最后一条记录的数据。

Any help on how to get multiple records to update is greatly appreciated. 非常感谢您对如何获取多个记录进行更新的任何帮助。

Thanks in advance. 提前致谢。

您可能正在寻找简单的表单关联帮助器: 链接

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

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