sajad torkamani

Rails's generator commands are awesome, allowing you to scaffold models, controllers, views, and a bunch of other things with a simple command like:

rails g controller articles

However, sometimes, and perhaps even often, we don't want helper files or Sass stylesheets.

For example, assuming we're using RSpec, running rails g controller articles will create a bunch of files and Rails helpfully prints out the names of these files like so:

create  app/controllers/articles_controller.rb
invoke  erb
create    app/views/articles
invoke  rspec
create    spec/requests/articles_request_spec.rb
invoke  helper
create    app/helpers/articles_helper.rb
invoke    rspec
create      spec/helpers/articles_helper_spec.rb
invoke  assets
invoke    scss
create      app/assets/stylesheets/articles.scss

We can tell Rails to skip the helper generator by passing a skip flag like --skip-helper or to skip the assets generator with the --skip-assets flag.

So running rails g controller articles --skip-helper --skip-assets would skip the helper and Sass files (things I usually want to skip) and result in fewer generated files:

create  app/controllers/articles_controller.rb
invoke  erb
create    app/views/articles
invoke  rspec
create    spec/requests/articles_request_spec.rb

Just another reason Rails is awesome!

Tagged: Rails