0
votes

just a quick question. I've been following a Rails tutorial and I've got to the point where I've the actions put in my controller. Something that's never happened before, maybe it's just a new Rails 5 thing, in my index action all I have is

@articles = Article.all

Yet when I look at the page online it's showing the articles followed by this at the bottom the page

[#<Article id: 8, title: "first title", description: "first", created_at: "2017-01-24 19:28:19", updated_at: "2017-01-24 19:28:19">]

And I have this in my index template

<p><%= link_to "Create new article", new_article_path %></p>

<%= @articles.each do |article| %>
<p><%= article.title %></p>
<p><%= article.description %></p>
<p><%= link_to "Edit", edit_article_path(article) %></p>
<p><%= link_to "Show", article_path(article) %></p>
<p><%= link_to "Delete", article_path(article), method: :delete, data: {confirm: "you sure?"} %></p>
<% end %>

I know you add code to the first line of the action to display params that are being passed but I don't have anything that would do this, is there any way to hide the extra info being displayed? I've tried searching online but I'm not sure if I'm using the correct term. Any help would be great

2

2 Answers

1
votes

The issue is right here

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

You need to use <% @articles.each do |article %> instead.

The <%= %> is printing out the array, which you don't want.

1
votes

Remove the equals sign from

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

By having it rails is doing something like

<%= @articles %>