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: <h2>Comments</h2> 8: <% for comment in @post.comments %> 9: <%= comment.body %> 10: <hr /> 11: <% end %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Daniel Higginbotham
2006-Sep-02 08:37 UTC
Re: New to Rails: Problem with adding comments to blog
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> 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: <h2>Comments</h2> > 8: <% for comment in @post.comments %> > 9: <%= comment.body %> > 10: <hr /> > 11: <% end %> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---