Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,440 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.