Skip to content

Instantly share code, notes, and snippets.

View jhonnatas's full-sized avatar
🎯
Focusing

Jhonnatas Alencar jhonnatas

🎯
Focusing
View GitHub Profile
@jhonnatas
jhonnatas / gist:46461dcdad3ef87477362f7351bbc5ad
Last active January 26, 2019 01:53
Ruby on Rails - Generating Scaffold with relationship
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