问题
I have a list of payment records in Payments#index. I've been asked to make that table directly editable and to have one button that saves all the updates. So far I've only partially managed to do this by wrapping each row around a form_for for that record like so:
<tbody>
<% @payments.each do |payment| %>
<tr>
<td><%= payment.client.trading_name %></td>
<td><%= payment.date_of_payment %></td>
<td>
<%= form_for payment do |f| %>
<%= f.text_field :amount %>
<%= f.submit 'Save', class: 'table_submit' %>
<% end %>
</td>
<td>
<%= form_for payment do |f| %>
<%= f.select :sequence_type, options_for_select(%w[RCUR OOFF FRST FNAL]) %>
<%= f.submit 'Save', class: 'table_submit' %>
<% end %>
</td>
<td>
<ul>
<li><%= link_to 'Edit', edit_payment_path(payment) %></li>
<li><%= link_to 'Destroy', payment, method: :delete, data: { confirm: 'Are you sure?' } %></li>
</ul>
</td>
</tr>
<% end %>
</tbody>
Is it possible to be able to edit all the records then have one update button instead of having to save each record individually? If so, how do I go about doing that?
回答1:
Its possible:
http://railscasts.com/episodes/165-edit-multiple-revised
And old version
http://railscasts.com/episodes/165-edit-multiple
来源:https://stackoverflow.com/questions/21850553/editing-multiple-rows-in-a-table-updating-multiple-records