0

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.

1 Answer 1

1

You have a td without closing tag(3rd one). Try after correcting it.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that's it. And pretty embarrassing. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.