New to Rails: Problem with adding comments to blog

Ok, so I’m following along with one of DHH’s screencasts, the one where
he’s creating a blog. Well. along the way he decides to add comments to
posts. In doing so he creates the model Comment and a table in the DB
called comments. I follow all of this and also create a has_many
relationship for posts with comments in the post.rb and a belongs_to
relationship for comments to posts in the comments.rb.

Well, as you can see by the error and the source below, something
happens when I go to add the comments to the show.rhtml.

Can anyone tell me why I’m getting this error?

-------------ERROR-------------

Showing app/views/content/show.rhtml where line #8 raised:

undefined method `comments’ for #Post:0x3600588

Extracted source (around line #8):

5:
6:
7:

Comments


8: <% for comment in @post.comments %>
9: <%= comment.body %>
10:

11: <% end %>

On Friday 01 September 2006 10:15 pm, Curmorpheus wrote:

Ok, so I’m following along with one of DHH’s screencasts, the one where
he’s creating a blog. Well. along the way he decides to add comments to
posts. In doing so he creates the model Comment and a table in the DB
called comments. I follow all of this and also create a has_many
relationship for posts with comments in the post.rb and a belongs_to
relationship for comments to posts in the comments.rb.

The convention for naming models is to use the singular form, so
“comments.rb”
should instead be “comment.rb”. If you named your class “Comments” it
will
need to be changed to “Comment”.

If you’re still having trouble it’d help to include the contents of
post.rb
and comment.rb as well

I hope this helps!
Daniel

You fixed my problem - thanks a bunch.

I actually had a posts.rb that was causing the issue, but exactly as
you had described it. I was using the plural version of the file name.
Not the singular.

Again, I really appreciate your quick answer. Thank you, thank you,
thank you.