“Rails generate” what?
To create a new rails application, one does:
rails new my_app
This one-line command installs 106 items at total size 315MB in a my_app directory, and lays out the framework for a basic web app.
Many things are installed in this folder, including Rack, ActiveRecord, ActiveModel, ActiveView — the major components of Rails framework, and other components of the rails framework.
Inside this project folder, one has access to rails command line tools, including: rails generate, rails console, rails server, rails dbconsole, etc. To see a complete list of rail command line tools, do:
bin/rails
As obvious as it is, outside the rails project folder, one does not have access to rail command line tools. Please note.
One important command to use is “rails generate”. This tool is used to generate new code, i.e., creating new files and filling in the default code in a few directories and enable the basic function of a web application. This simple act of kindness saves developers not only the typing work, but also the brain work, of jumping back and forth and keeping track of who does what where.
This philosophy and goal is pretty much the essence of Rails framework.
As with any other powerful tools, one needs to be judicious about when to use what. Otherwise, one may end up with a whole house full of stuff you never use — you can never find things and you dare not to throw away things. With time one becomes a non-lean-person.
So “rails generate” what?
Use “rails generate -h” to list your choices. There are 17 things you can generate, but most often used are:
migration, model, controller, resource, routes, scaffold
Here is a comparison of the files and folders generated by each generator.

Here is another way to look at it, from the least to the most:
- migration: migration only
- model: migration + model
- controller: controller + a views folder
- resource: migration, model, controller, routes
- scaffold_controller: controller + views
- scaffold: migration, model, control, route, views, and many other things
Here is a very good analysis of different generators. It explains why generate scaffold is not a good idea in general, and that resources generator is a best option to create a lean rails framework with its most magic components.
Here are notes on the other two generators:
- Model generator gets used regularly, it creates a model and associated database table.
- Controller generators are great for creating static views or non-CRUD related features. Note if you use “rails g controller student”, it actually create controller in singular form. student_controller, as vs. to students_controller in controllers generated by other generators.
And here is an example for syntax:
rails g resource Account title room_number:integer --no-test-framework --no-helper --no-stylesheets --no-assets --no-test-framework
Naked scaffold
If you indeed want to use scaffold, here is a simple script to not to generate the extra files.
First at rails install, you can skip some things such as test suite using
rails new plumber --skip-test
Inside rails project, use below to get simple naked mcv files and directory:
rails generate scaffold cello --no-helper --no-jbuilder --no-api --no-asset --no-scaffold-stylesheet --no-stylesheets
The script above is a bit long, Kevin McAlear suggested that I made it into a bash command. Here it is.
And you can do this line in your rails project folder to generate a naked scaffold:
rails_naked_scaffold.sh cello
Go in right way and look through everything. I like to keep all the links, but delete generic code that does not make sense. Don’t yield to the thought that you might need it later, you can always create later when you need it.
One great power of scaffold is to generate whole set of crud views. What could be even powerful is to add model attributes automatically if you have exisiting schema and model.
rails g scaffold_controller User name email
If you want have many existing attributes for the model, you can use
rails g scaffold_controller User User.column_names.join(" ")As 2.6.1 :002 > User.column_names.join(" ")=> "id name created_at updated_at"