-1

I have a rails app with the database containing seeded objects. When I access them in a view, all of them get printed onto the bottom of the page. Has anyone else experienced this problem?

Here is the code in the view:

<%= @articles.each do |article| %>
<h2><%= link_to "#{article.title}", title_path(article.index), {class: "link"} %></h2>
<p><%= article.text[0..article.text.index('.')] + "..." %></p>

And here is what is rendered (The blue link and line under is supposed to render, but then all of the seeded articles render):

genghiskhan
  • 1,086
  • 10
  • 16

1 Answers1

1

There is an error in this line

<%= @articles.each do |article| %>

The '=' character outputs the result of that line. Without the '=' character, the code is evaluated without being printed. Remove the '=' and you should not see the output of the @articles variable.

<% @articles.each do |article| %>

This question may help.

Community
  • 1
  • 1
margo
  • 2,819
  • 1
  • 9
  • 28