Is there a way with the usual generators config to turn OFF the creation of the view folders and action templates when you run a rails generate controller
?
To skip views from being generated with your controller, disable the template engine.
Once:
rails g controller ControllerName action1 action2 --skip-template-engine
Note that every --skip
option also has an aliased --no
option.
Default:
# config/application.rb
config.generators do |g|
g.template_engine false
end
# OR
config.generators.template_engine = false
If you have an API-only application (no front end), you may also want to skip assets and helpers from being generated with your controllers.
Once:
rails g controller api/users --no-helper --no-assets --no-template-engine
Default:
# config/application.rb
config.generators do |g|
g.assets false
g.helper false
g.template_engine false
end
# OR
config.generators.assets = false
config.generators.helper = false
config.generators.template_engine = false
Disabling assets skips stylesheets and javascripts from being generated. If you only want to skip one, use --no-stylesheets
or --no-javascripts
, or in config/application.rb
use:
config.generators.stylesheets = false
config.generators.javascripts = false
If your default configuration skips something from being generated (e.g. assets and helpers) but you need them in one case, you can generate them like so:
rails g controller foo --helper --assets --skip
where --skip
skips generating files that already exist.