Suppress Rails from generating controller specific asset files

Written by Michael Lee 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.

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.