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
?
I can't find an option anywhere and the code here doesn't show me any pointers.
We are likely going to be building our own controller / resource generators at some point anyway, for our API, but I was curious if there was a way to turn off this annoyance in the meantime.
If you're creating an API with no front end, you can go ahead and use
rails new --api
. However, I don't recommend this option if you do plan to create a front end (for example a single page app) because it turns a lot of things off, including the asset pipeline.It's not a well documented feature, but try to add
--skip-template-engine
(alias--no-template-engine
) option to the command.demo on a dummy app:
To skip views from being generated with your controller, disable the template engine.
Once:
Note that every
--skip
option also has an aliased--no
option.Default:
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:
Default:
Disabling assets skips stylesheets and javascripts from being generated. If you only want to skip one, use
--no-stylesheets
or--no-javascripts
, or inconfig/application.rb
use: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:
where
--skip
skips generating files that already exist.Just thought I'd try underscoring the --skip-template-engine flag to see if it worked in a generator and it worked a charm! No view templates generated from a
bin/rails g controller
command in a Rails 4.2 application.Try:
A little late I know but these things stick around in Google! ;)