Editing multiple rows in a table (updating multiple records)

元气小坏坏 提交于 2019-12-10 11:46:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!