Adding files to config.assets.precompile in Rails 3.1+

I came across a problem that stumped me for quite a while today, so thought it best I write it down.

In Rails 3.1+ with the asset pipeline enabled any files that are not referenced by a manifest file (e.g. a require line) will not be precompiled in production. They may work fine in development / compiling on the fly but they won’t be touched by the assets:precompile rake task.

The solution is to add them to config.assets.precompile in your application.rb file. However there is a little gotcha. I had a file I wanted precompiled called admin.sass, so I wrote the following line:

config.assets.precompile += %w(admin.sass)

However this didn’t work. Eventually I found out it’s because the asset pipeline expects you to specify the resulting filename after compilation, rather than the un-compiled SASS/CSS filename. So I changed the line:

config.assets.precompile += %w(admin.css)

Everything worked fine then.

This entry was posted in Blog, Noteworthy, Ruby. Bookmark the permalink.
  • Anonymous

    Oh, thank you. I was walking in circles in the problem.

  • http://www.deploymentzone.com Charles Feduke

    Awesome, was trying to figure out why after I went through all the trouble of breaking up stuff to handle ie6/ie7 with IF conditionals that my Heroku dyno was dying when a request came in.  Thanks!

  • http://profiles.google.com/joevandyk Joe Van Dyk

    This is really really really annoying. :( This means the problem only happens in staging/production, not in development. 

  • Sheng Loong

    “Eventually I found out it’s because the asset pipeline expects you to specify the resulting filename after compilation, rather than the un-compiled SASS/CSS filename.”

    You’ve just saved my life dude! thanks :)

  • Nick Hammond

    Thanks for this post, the documentation on how the pre-compilation works is a bit lacking I think, this helped to clear a few assumptions up.

  • Thiago C

    Thanks man!

  • Antonio Pagano

    thank you!