Suppress Rails from generating controller specific asset files

Written on July 30, 2016

By default, Rails will generate a JavaScript file and a CSS file (or CoffeeScript and Sass if you’re using the coffee and sass -rails gems) when you generate a controller.

I personally like to structure my asset files differently instead of being controller specific. For this reason, I choose to have Rails suppress the automatic generation of asset files when controllers are generated.

To do this, you’ll want to add this bit of code in your config/application.rb file.

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

So your final file should look something like this:

...
module App 
  class Application < Rails::Application
    config.generators do |g|
      g.assets false
    end
  end
end

Now whenever you generate a controller, the asset files won’t be generated, leaving it up to you to create and structure your asset files the way you want it.

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share articles like this one in your inbox. Sign up for my newsletter.