Hi I am new to Ruby on Rails. I am trying to create a small blog site. I have two tables Posts and Comments. Each Post will have many comments. I generate the tables using these commands.
rails g scaffold Post title:string body:text author:string
rails g scaffold Comment body:string author:string
Now I want to add the relationship to the model classes. I add has_many :comments
to the Post class and belongs_to :post
to the Comment class. However when I try to call post.comments
I get a runtime error saying SQLException: no such column: comments.post_id
. Should I create a migration and add post_id under Comment or is there a way to achieve this when scaffolding?