[Rails Guides] Getting Started 7.4 - Array Output Problem

Hey Guys, i'm new on rails and started with the Rails Guide: Getting Started with Rails

In section 7.4 I have a problem. I implemented the code as stated and when I add a comment it works fine. When I want to show the comment I get the following output under my comment:

[#<Comment id: 1, commenter: "Tester", body: "This is a test comment", post_id: 1, created_at: "2012-03-07 11:48:02", updated_at: "2012-03-07 11:48:02">]

Can somebody tell me where this come from?

Could you post the code of the show.html.erb? (because you’re saying that it happens in the “show” action)

Javier Q.

You're possibly doing this:

<%= @my_object.comments.each do |comment| %> .... # and then code to output the comment <% end %>

rather than:

<% @my_object.comments.each do |comment| %> .... # and then code to output the comment <% end %>

The equals sign before the iterator will output to the browser the result of the iterator (which will be the collection that's iterated). You can see the Comment displayed has square brackets around it, which indicate it's a single element array - so probably a collection that's being rendered by mistake.

Thats the point! Thank you so much!