私の Ruby on Rails アプリは、ループを反復するときに「ファントム」オブジェクトを返します。ここでの問題は、次のように場所の配列を設定する SQL コマンドがコントローラー ファイルにあることです。
@locations = Location.select(
'distinct location_address_1,location_city
,location_state,location_zip').where(
'(SELECT COUNT(*) FROM item_data
WHERE item_data.location_id = locations.id)')
問題は、ビュー ファイルを反復処理するときに余分な空白が発生することです。この質問が何度か出されたのを見たことがありますが、解決策はありません。このコードが私のview.html.erbに書かれている理由を誰かが知っていますか
<table id="myTable">
<thead>
<tr>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
</tr>
</thead>
<tbody>
<% @locations.find_each do |location| %>
<tr>
<td>1</td>
<td>2</td>
<td>3<td>
<td>4</td>
</tr>
<% end %>
</tbody>
</table>
私のブラウザでは次のように出力されます:
<table id="myTable">
<thead>
<tr>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td/>
<td>4</td>
</tr>
</tbody>
</table>
上記のように、データをハードコーディングしても余分な空白が発生します。