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.