Model Generator in Ruby
From the Ruby on Rails cheat sheet · Generators · verified Jul 2026
Model Generator
Generate models with migrations and attributes
bash
# Basic model
rails generate model User name:string email:string
# Model with references
rails generate model Post title:string body:text user:references
# Model with indexes
rails generate model Product name:string:index price:decimal✅ Automatically creates migration, model, and test files
💡 Use references for associations (creates foreign key)
🔍 :index adds database index, :uniq adds unique index
⚡ rails destroy model reverses the generator
generatormodelmigration