I've just stated programming with Ruby on Rails a few days ago. I'm
trying to set up a simple Blog. To this point I have a Posts.rb model
and controller and a comments.rb model and controller with a "has_many
:comments" in posts.rb and a "belongs_to :posts" in comments.rb.
Furthermore, the comments table has a post_id column of type integer (Am
I right in that this is supposed to be automatically assigned the id of
the post p when p.comment.new() is called?).
However, in the ruby console after assigning a post object to p (>> p =
Posts.find(1)) the command
p.comment.new(:author => 'me', :content => 'Enter all the content you desire here...')
returns the error:
NoMethodError: undefined method `comment' for #<Posts:0x19673f4>
I get the same error when I use p.comment.create and p.comment.build
When I execute
p.comments.new(:author => 'me', :content => 'Enter all the content you desire here...')
I get the error:
NameError: uninitialized constant Posts::Comment
What am I doing wrong? Is there another method I'm supposed to be
coding? Are there more steps to creating a relationship other than 1)add
has_many to the parent, 2) add belongs_to to the child and 3)ensure
childl has a parent_id column?
Thanks you for any help you an give me! I've been trying to look on
forumns but haven't yet found someone with the same problem...