编辑表中的多行(更新多条记录) [英] Editing multiple rows in a table (updating multiple records)

查看:84
本文介绍了编辑表中的多行(更新多条记录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Payments#index中有一个付款记录列表。我被要求使该表可以直接编辑,并需要一个按钮来保存所有更新。到目前为止,我仅通过将每一行都围绕该记录的form_for来部分地做到了这一点,例如:

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?

推荐答案

有可能:

http://railscasts.com/episodes/165-edit-multiple-revised

和旧版本

http://railscasts.com/episodes/ 165-edit-multiple

这篇关于编辑表中的多行(更新多条记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆