Rails 3 submit a form with multiple records

后端 未结 2 938
夕颜
夕颜 2020-11-29 01:36

I\'m new to rails so this is probably a basic question. I am trying to create a form where the user can create 3 records at once. I want the user to only have to click the

2条回答
  •  被撕碎了的回忆
    2020-11-29 01:50

    You'll need to tell rails its an array. First, read this section of this article:

    For your purpose, you'll need to build the form by hand:

    <%= form_tag 'foo' do %>
      <% [1,3,5].each do |i| %>
        <%= text_field_tag 'review[][name]' %>
        <%= text_field_tag 'review[][comment]' %>
        <%= hidden_field_tag 'review[][rating]', :value => i %>
      <% end %>
    <% end %>
    

提交回复
热议问题