2

I am getting doubled output on my page when the following code executes, what am I not seeing? I do not want the text inside the [].

<dt>Publications</dt>
            <dd>
                <ul>
                    <%= @person.pubs.each do |pub| %>
                        <li><%= pub.authors %>, <%= pub.title %>, <%= pub.journal %>, <%= pub.date %>, <%= pub.link %></li>
                    <% end %>
                </ul>
            </dd>

The output looks like the following:

Publications

    Thiebaud N, Johnson MC, Butler JL, Bell GA, Ferguson KL, Fadool AR, Fadool JC, Gale AM, Gale DS, Fadool DA, Hyperlipidemic diet causes loss of olfactory sensory neurons, reduces olfactory discrimination, and disrupts odor-reversal learning., J. Neurosci., 2014,
    [#<Pub id: 1000, person_id: 7, pubmed_id: nil, journal: "J. Neurosci.", title: "Hyperlipidemic diet causes loss of olfactory sensor...", auth_id: "Fadool DA", authors: "Thiebaud N, Johnson MC, Butler JL, Bell GA, Ferguso...", pages: "34(20):6970-84", date: "2014", type: nil, link: nil, notes: nil, created_at: nil, updated_at: nil>] 

This text also includes information that is not being called in my code.

Argent
  • 303
  • 1
  • 12

1 Answers1

2
<%= @person.pubs.each do |pub| %>
    <li><%= pub.authors %>, <%= pub.title %>, <%= pub.journal %>, <%= pub.date %>, <%= pub.link %></li>
<% end %>

should be

<% @person.pubs.each do |pub| %>
    <li><%= pub.authors %>, <%= pub.title %>, <%= pub.journal %>, <%= pub.date %>, <%= pub.link %></li>
<% end %>

(notice there is no = sign on the line where you perform the .each loop).

<%= is a print statement. .each returns the collection, therefore the result in your case is a double output: one from the inner loop and one from .each.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364