Masatoshi Nishiguchi
Software Engineer

Rails generate memo

rails

The rails generate command

# List all the available generators
$ rails generate

controller

# Usage: `rails generate controller NAME [action action] [options]`
# Help:  `rails generate controller`

$ rails generate controller Users new

model

# Usage: `rails generate model NAME [field[:type][:index] field[:type][:index]] [options]`
# Help:  `rails generate model`

$ rails generate model User name:string email:string

migration

# Usage: `rails generate model NAME [field[:type][:index] field[:type][:index]] [options]`
# Help:  `rails generate migration`

# Add an index on the email column of the users table.
$ rails generate migration add_index_to_users_email

resource

Stubs out a new resource including:

# Usage: `rails generate resource NAME [field[:type][:index] field[:type][:index]] [options]`
# Help: `rails generate resource`

$ rails generate resource post title:string body:text published:boolean

scaffold

Generates a full set of:

# Usage: `rails generate scaffold NAME [field[:type][:index] field[:type][:index]] [options]`
# Help: `rails generate scaffold`

$ rails generate scaffold post title body:text published:boolean

Reference