'Syntax to skip creating tests, assets & helpers for `rails generate controller`?
I read the help & tried the following command to skip generation of tests, assets & helper files
$ bin/rails generate controller home index --helper false --assets false --controller-specs false --view-specs false
create- app/controllers/home_controller.rb
route get "home/index"
invoke erb
create app/views/home
create app/views/home/index.html.erb
invoke rspec
error false [not found]
error false [not found]
As you may notice by output above this works & only controller, routes & views are generated. But as last two lines are interesting:
error false [not found]
error false [not found]
Obviously rails doesn't seem to like --option-name false syntax. so this this error because I used the wrong syntax? If yes, then what is the correct way? Thanks
Solution 1:[1]
To turn off without having to add options:
# application.rb
config.generators.assets = false
config.generators.helper = false
Solution 2:[2]
Applications which serve only API will not require javascript, stylesheet, views, helpers. To skip those files in generator/scaffold for Rails 3.x add the below code block in the application.rb
#to skip assets, scaffolds.css, test framework, helpers, view
config.generators do |g|
g.template_engine nil #to skip views
g.test_framework nil #to skip test framework
g.assets false
g.helper false
g.stylesheets false
end
check the link for more details about generators
Solution 3:[3]
More concisely:
rails g controller home index --no-assets --no-test-framework
Solution 4:[4]
Inside application.rb file write: This will stop generating everything apart from what is written in the command line
config.generators do |g|
g.test_framework nil
g.template_engine nil
g.assets false
g.helper false
g.stylesheets false
g.javascripts false
end
Example:
vidur@vidur-desktop:~/Downloads/tukaweb$ rails g controller uploader/three_d_models
Running via Spring preloader in process 3703
create app/controllers/uploader/three_d_models_controller.rb
invoke assets
invoke js
invoke scss
for one liner solution =>
rails g controller assets_garments --skip-test-framework --skip-assets --skip-helper
Solution 5:[5]
If you want to generate only controller, nothing else.
rails g controller [controller_name] [index] --no-helper --no-assets --no-template-engine --no-test-framework
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kris |
| Solution 2 | |
| Solution 3 | Erik Trautman |
| Solution 4 | notapatch |
| Solution 5 | Jin Lim |
