1

我有一个嵌套表单,其中显示了一些用于 has_many 关系的字段。当我渲染包含字段的部分时,我的 tr 和 td 标记被删除。然而, div 标签不是。我可以做些什么来确保标签没有被剥离?

_form.html.erb

<%= form_for @invoice do |f>
.
.
.
<table>
  <th>Qty</th>
  <th>Description</th>
  <th>Price</th>
  <th>EA/C</th>
  <th>Amount</th>

  <%= f.fields_for :invoice_line_items do |builder| %>
    <%= render 'invoice_line_item_fields', :f => builder %>
  <% end %>
</table>

<% end %>

在浏览器源代码中查看的 table 标记仅包含标题并在呈现嵌套表单部分之前关闭。部分完全剥离所有 tr 和 td 元素。

_invoice_line_item_fields

<div>
  <tr>
    <td>
      <%= f.text_field :qty %>
    </td>
    <td>
      <%= f.text_field :description %>
    </td>
    <td>
      <%= f.text_field :price %>
    </td>
    <td>
      <%= f.text_field :ea_c %>
    </td>
    <td>
      <%= text_field_tag :amount %>
    </td>
    <td>
      <%= f.hidden_field :_destroy %>
      <%= link_to "remove", "#", :class => "remove_line_items" %>
    </td>
  </tr>
</div>
4

1 回答 1

0

As others have pointed out in the comments your markup is incorrect and what the browser shows you might be highly modified due to it trying to guess what you actually meant.

A correct structure for a table would be:

<table>
  <thead>
    <th>Header1</th>
    <th>Header1</th>
  </thead>
  <tbody>
    <tr>
      <td>You can have divs here ...</td>
      <td>You can have divs here ...</td>
    </tr>
  </tbody>
</table>

Don't mix in other HTML elements except inside your <td>...</td>-tags and you should be fine...

于 2013-01-29T08:03:33.617 回答