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

コメントで他の人が指摘しているように、あなたのマークアップは正しくなく、実際に何を意味しているのかを推測しようとするため、ブラウザーが表示する内容は大幅に変更されている可能性があります。

テーブルの正しい構造は次のようになります。

<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>

-tags以外の他の HTML 要素を混ぜないでください。<td>...</td>問題ないはずです...

于 2013-01-29T08:03:33.617 に答える