当我用表格包装表格时,Rails会消失复选框

时间:2015-08-27 01:51:47

标签: ruby-on-rails ruby-on-rails-4

我不确定这里发生了什么。当我将表格包裹在桌子周围时,桌子消失了。当我删除表单时,表重新出现。提前致谢。这是代码:

<% form_tag deposit_checks_path :method => :put do %>

    <table>
      <thead>
        <tr>
          <th>Checkbox</th>
          <th>Date</th>
          <th>Mailer ID</th>
          <th>Payment amt</th>
          <th>Transaction type</th>
          <th>Transaction</th>
          <th>Deposit</th>
          <th>User</th>
          <th colspan="3"></th>
        </tr>
      </thead>

      <tbody>

        <% @payments.each do |payment| %>
          <tr>
            <td><%= check_box_tag "payment_id[]", payment.id, checked = false %></td>
            <td><%= payment.created_at %></td>
            <td><%= payment.mailer_id %></td>
            <td><%= number_to_currency(payment.payment_amt) %></td>
            <td><%= payment.transaction_type %></td>
            <td><%= payment.transaction_id %></td>
            <td><%= payment.deposit_id %></td>
            <td><%= payment.user_id %></td>
            <td><%= link_to 'Show', payment %></td>
            <td><%= link_to 'Edit', edit_payment_path(payment) %></td>
            <td><%= link_to 'Destroy', payment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
            </tr>
           <% end %>
           </tbody>
    </table>
<%= submit_tag "Edit Checked" %>
<% end %>

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

试试这个

<table>
<thead>
  <tr>
   <th>Checkbox</th>
    <th>Date</th>
    <th>Mailer ID</th>
    ..
    ..
  </tr>
</thead>
<tbody>
  <tr>
    <td>
      <% form_tag deposit_checks_path :method => :put do %>

        <table>
           <% @payments.each do |payment| %>
          <tr>
             <td><%= check_box_tag "payment_id[]", payment.id, checked = false %></td>
            <td><%= payment.created_at %></td>
            <td><%= payment.mailer_id %></td>
            ...
            ...

          </tr>
          <%end%>
        </table>
      <% end %>
    </td>
  </tr>
</tbody>
</table>

答案 1 :(得分:0)

你在代码中注意到了吗?

<% form_tag deposit_checks_path :method => :put do %>

您忘了添加comma。应该是

<% form_tag deposit_checks_path, :method => :put do %>

否则method: :put会附加到action属性 enter image description here

要点:

  

您忘记在form_tag

之前加上等号

试试这个

<%= form_tag deposit_checks_path, :method => :put do %>