This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scaffold actually provides a way to generate relationships, you should use the :references data type | |
rails g scaffold Comment body:string author:string post:references | |
This will generate a migration for the comments table with a post_id field and index for it. The generator will also add belongs_to :post to the Comment model. | |
It will not however generate the reverse side of the relationship so you'll need to add | |
has_many :comments |