Precompile Static HTML Pages with Rails 3 Asset Pipeline

At CarWoo we recently upgraded all the way from Rails 2.3.8 to 3.2 and with that brought the asset pipeline. We probably could have skipped the asset pipeline but we figured we should throw in it for good measure. One of the problems that we ran into was including some of the compiled javascript and stylesheet files from the assets directory into our 404 and 500 error pages. In Rails 2.3, we just created static html pages and threw them in the public folder and didn't think about them ever again. Unfortunately, since the Rails 3 asset pipeline adds and MD5 hash to the js and css files names, statically linking them wasn't going to work.


I wish I could take credit for this, but the honorable @sshconnection recommended that we just precompile 404 and 500 pages as well. And wouldn't you know that, it was way easier than you think it could be.


First get your config in place:


Just like any Rails convention, add the extensions to want to use to precompile. In my case, I used erb in my 404 page:


This probably should be labelled as a quick tip, but it was a little a-ha moment for me and I figured I'd share it.

blog comments powered by Disqus