How do I turn off automatic stylesheet/javascript

2019-02-01 05:32发布

问题:

I've got a Rails 3.1 project that I'm working on, but I don't want controller_name.css.sass and controller_name.js.coffee to be generated each time I run rails generate controller controller_name. I could swear I've seen the setting somewhere on the internet, but I can't find it now for the life of me. What is it?

Keep in mind that I'm still wanting to use the Asset Pipeline and the CoffeeScript/Sass integration, but I'm organizing those files in my own way.

I'm pretty sure the answer is a command line argument, but bonus points for turning it off with a generator setting or a hidden file or something.

EDIT: I've found the command line flag for it.

rails generate controller controller_name --assets=false

Or something of the like (that line actually errors out, but it also doesn't generate the assets). The API here shows :assets => true as a default option. How do I change that to false and have it always be false every time I generate a controller?

回答1:

Add these lines to application.rb:

config.generators.stylesheets = false
config.generators.javascripts = false


回答2:

New syntax is rails generate controller Resources --no-assets.

Don't forget you can also use g in place of generate. And you can skip the creation of a controller helper using the --no-helper flag.



回答3:

For just one time, use:

rails generate controller controller_name --no-assets


回答4:

An update on @Dmitry Maksimov's answer for Rails 4.2. You can disable generation of controller-specific asset files by default with the following in your config/application.rb file (source: the guide):

config.generators do |g|
  g.assets false
end


回答5:

My whole options:

config.generators do |g|
    g.stylesheets = false
    g.javascripts = false
    g.test_framework  :rspec, fixture: false
    g.template_engine :haml
    g.fixture_replacement :factory_girl, dir: 'spec/factories'
end