Syntax to skip creating tests, assets & helpers for `rails generate controller`?

Ruby on-RailsRuby on-Rails-3Generator

Ruby on-Rails Problem Overview


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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Try using --no- followed by optionname:

rails generate controller home index  --no-helper --no-assets --no-controller-specs --no-view-specs

If you want to change the default behavior every time you run the generator command, you can configure the defaults you would like in the application.rb file - see https://stackoverflow.com/questions/4235264/how-can-i-make-sure-rails-doesnt-generate-spec-tests-for-views-and-helpers.

Solution 2 - Ruby on-Rails

To turn off without having to add options:

# application.rb
config.generators.assets = false
config.generators.helper = false

Solution 3 - Ruby on-Rails

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 4 - Ruby on-Rails

More concisely:

rails g controller home index --no-assets --no-test-framework

Solution 5 - Ruby on-Rails

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 6 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCuriousMindView Question on Stackoverflow
Solution 1 - Ruby on-RailsPinnyMView Answer on Stackoverflow
Solution 2 - Ruby on-RailsKrisView Answer on Stackoverflow
Solution 3 - Ruby on-RailsArivarasan LView Answer on Stackoverflow
Solution 4 - Ruby on-RailsErik TrautmanView Answer on Stackoverflow
Solution 5 - Ruby on-Railsvidur punjView Answer on Stackoverflow
Solution 6 - Ruby on-RailsJin LimView Answer on Stackoverflow