0

I have a pretty simple ERB file that loops through a database and spits out data formatted for Bootstrap specific to certain users. Everything looks great, but at the end after all the divs, it includes output that looks like it would if you used the console to filter for items with the same user_id.

I feel like I'm just missing something simple, but I can't find it. Also, the else statement correctly outputs if I destroy all the deals for a given user.

file

<% if @user.deals.any? %>
    <%= @deals.each do |deal| %>
        <div class="row">
            <div class="col col-xs-12">
                <%= deal.headline %>
            </div>
        </div>
        <div class="row">
            <div class="col col-xs-3">
                <%= deal.client %>
            </div>
            <% if deal.matter? %>
                <div class="col-xs-3">
                    <%= deal.matter %>
                </div>
            <% end %>
            <% if deal.summary? %>
                <div class="col-xs-6">
                    <%= deal.summary %>
                </div>
            <% end %>
        </div>
    <% end %>
<% else %>
    <div class="row">
        <div class="col col-xs-12">
            <h4>Add your first deal to see a list here!</h4>
        </div>
    </div>
<% end %>

additional output after rows of data

[#<Deal id: 18, client: "Headline and client only", matter: "", summary: "", user_id: 2, created_at: "2017-02-08 15:09:28", updated_at: "2017-02-08 15:09:28", headline: "Healine and client only">, #<Deal id: 17, client: "First client", matter: "First matter", summary: "First summary", user_id: 2, created_at: "2017-02-08 15:07:45", updated_at: "2017-02-08 15:07:45", headline: "First headline">]

1 Answers1

1

Instead

<%= @deals.each do |deal| %>

use

<% @deals.each do |deal| %>

notice = gone

Refer What is the difference between <%, <%=, <%# and -%> in ERB in Rails? for more information ;-)

Community
  • 1
  • 1
mswiszcz
  • 961
  • 1
  • 7
  • 23
  • Works, thank you! Thanks also for the link, that's good info :) I'm curious, why did it come out correctly, but with the console output? – oneWorkingHeadphone Feb 08 '17 at 15:38
  • 1
    cos it is running the block but also outputting what .each is returning (and since it allows you to chain methods, it is returning @deals), see here: http://paste.ubuntu.com/23954994/ - you can try it urself in irb, just pick any array, do each, and see what methods returns. – mswiszcz Feb 08 '17 at 15:54