Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Post index page displays unneeded info

On my posts index page it simply lists each post, but then after it displays this:

[#<Post id: 1, content: "This is a post", created_at: "2014-07-27 18:06:09", updated_at: "2014-07-27 18:06:09">, #<Post id: 2, content: "This is another post", created_at: "2014-07-27 18:06:19", updated_at: "2014-07-27 18:06:19">]

My Post controller is:

class PostsController < ApplicationController
    def index
        @posts = Post.all
    end
end

And index.html.erb

<ul>
<%= @posts.each do |post| %>
    <li>
        <%= post.content %>
    </li>
<% end %>
</ul>

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Remove the = symbol from this: <%= @posts.each do |post| %>. You only want the selected content to be printed and the = prints every post with all its attributes. If it's <% @posts.each do |post| %> - the logic is executed, but is not printed in the view.