0

I have this in my html.erb file:

<%= @pg_search_documents.each do |result| %>
    <%= simple_format(result.content) %><br><br>
<% end %>

The output is the following:

nadja kuhn


Zwischen Nadja Dazwischen


[#<PgSearch::Document id: 17, content: "nadja kuhn", searchable_id: 122, searchable_type: "Event", created_at: "2016-03-18 22:45:02", updated_at: "2016-03-18 22:45:02">, #<PgSearch::Document id: 19, content: "Zwischen Nadja Dazwischen", searchable_id: 124, searchable_type: "Event", created_at: "2016-03-18 22:45:02", updated_at: "2016-03-18 22:45:02">] 

The first two lines are printed as expected, but somehow, there comes more, than just the content, namely, the list with the whole entries.

If I write this:

<%= @pg_search_documents.each do |result| %>

The first two lines disappear, as expected, but somehow, there is still this list:

[#<PgSearch::Document id: 17, content: "nadja kuhn", searchable_id: 122, searchable_type: "Event", created_at: "2016-03-18 22:45:02", updated_at: "2016-03-18 22:45:02">, #<PgSearch::Document id: 19, content: "Zwischen Nadja Dazwischen", searchable_id: 124, searchable_type: "Event", created_at: "2016-03-18 22:45:02", updated_at: "2016-03-18 22:45:02">] 

If I write nothing, then nothing happens. What do I need to do, that this second list doesn't get printed?

Mohamad
  • 34,731
  • 32
  • 140
  • 219
Metaphysiker
  • 983
  • 2
  • 18
  • 35

1 Answers1

2

That's because you are outputing the line of your iterator:

<%= @pg_search_documents.each do |result| %>

Notice the extra =, which essentially calls to_s under the hood. Take it out.

<% @pg_search_documents.each do |result| %>

See this question on the difference between <% ... %> and <%= ... %>.

Community
  • 1
  • 1
Mohamad
  • 34,731
  • 32
  • 140
  • 219