Take the 2-minute tour ×

I am building a static public/404.html page. Before Rails 3.1 I can reference it with the public/style.css. But now with asset pipeline I am not sure what to link to. I heard that the styles will be compiled into asset/application.css. But on production it will come with a timestamp.

What is the best approach to style the static 404.html with the normal styles I work with?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

It's true that the assets in 3.1 come with a digest in production, but you can still use the regular file, meaning that you can link to /assets/application.css and you won't have any problems (try it! :)).

share|improve this answer
Thanks! I guess this means I can't check those in development environment? As in dev css files are not merged. –  lulalala Dec 23 '11 at 6:39
You should be able to do it too. If you call /assets/application.css you'll see all the concatenated code. If you call it with the ?body=1 option you'll only see what's in that specific file. –  Federico Builes Dec 23 '11 at 19:36
...and if you're using far-future expiration headers then doesn't this solution leave you pretty screwed? What if you update your application.css and the users already have that file cached. They'll not get your updated styles. –  crankharder Feb 8 '12 at 4:36
Since Rails 4.0, there are no assets generated without digest. –  Petr Jun 2 at 13:24
add comment

You can precompile static error pages with asset pipeline too!

Inside application.rb:

config.assets.precompile += %w(404.html 500.html)

Create in assets/html/ files 404.html.erb and 500.html.erb and use many helpers there, like stylesheet_link_tag, javascript_include_tag, image_tag.

Then setup your server to use precompiled public/assets/404.html and public/assets/500.html

All credits for this clever solution goes to http://neovintage.blogspot.cz/2012/02/precompile-static-html-pages-with-rails.html

share|improve this answer
In Rails 4, this is also necessary: stackoverflow.com/questions/14284278/… –  Petr Aug 12 '13 at 15:18
Also they MUST be erb files, not HAML icelab.com.au/articles/… –  ClothSword Oct 14 '13 at 14:42
There is another nice solution for HAML error pages: devoh.com/blog/2012/09/asset-pipeline-error-pages –  Darkside Nov 2 '13 at 18:23
add comment

Your Answer


