40

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?

Ben Kreeger
  • 6,355
  • 2
  • 38
  • 53
  • 2
    if you add `-h` to the end of a rails command it'll give you the help file: `rails g controller -h` – greggreg Sep 09 '11 at 19:49

5 Answers5

87

Add these lines to application.rb:

config.generators.stylesheets = false
config.generators.javascripts = false
Dmitry Maksimov
  • 2,861
  • 24
  • 19
  • That is so awesome. I was able to verify that it works. Thanks! – Ben Kreeger Sep 13 '11 at 16:50
  • 5
    This one-liner does the same `config.generators.assets = false` – Dennis Feb 05 '15 at 12:10
  • Nice permanent solution. Probably only needs to go into `development.rb` not `application.rb` since it only applies to development environment. – Lars Levie Feb 10 '15 at 18:04
  • 3
    summarizing, `environments/development.rb`, `config.generators.assets = false` and for no helpers, `config.generators.helper = false` – max Mar 23 '15 at 02:53
21

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.

Lars Levie
  • 795
  • 6
  • 9
10

For just one time, use:

rails generate controller controller_name --no-assets
Dreammm
  • 101
  • 1
  • 3
  • 2
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/faq#reputation) you will be able to [comment on any post](http://stackoverflow.com/privileges/comment). – Roman C Feb 22 '13 at 09:12
  • @RomanC Uh, what? As far as I can tell, it does provide an answer to the question. It says how to turn off automatic asset generation, albeit just for one run of the command. – Nic Dec 15 '15 at 19:57
7

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
Lucas Nelson
  • 2,511
  • 1
  • 17
  • 14
1

My whole options in the application.rb file:

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
aarkerio
  • 2,183
  • 2
  • 20
  • 34