Reputation: 64
My Ruby on Rails app returns 'phantom' objects when iterating through my loop. The issue here is I have a SQL command in my Controller file that sets my locations array like so:
@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)')
Problem is I get extra blanks when iterating through in my view file. I have seen this question asked a few times with no solution. Does anyone know why this code written in my 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>
Outputs as this in my browser:
<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>
As shown above, I get the extra blank even when hardcoding my data.
Upvotes: 0
Views: 103
Reputation: 29349
You have a td without closing tag(3rd one). Try after correcting it.
Upvotes: 1