For anyone's convenience, I adopted Richard's solution in my project and created a simple ruby script that replaces asset links in the static HTML error / maintenance pages. It is deliberatery NOT a rake task so that it is as fast as possible. It has no Rails depenency anyway, other than that it has to be run from the rails root directory.
#!/usr/bin/env ruby
require 'yaml'
GLOBS = %w(public/errors_source/*.html)
MANIFEST = "public/assets/manifest.yml"
manifest = YAML::load(File.open(MANIFEST))
GLOBS.each do |glob|
Dir.glob(glob).each do |file|
next unless File.file?(file)
contents = File.read(file)
manifest.each do |asset, compiled_asset|
contents.gsub!(asset, "/assets/#{compiled_asset}")
end
File.open(file.gsub('errors_source/',''), 'w') do |outfile|
outfile.write(contents)
end
end
end
The script expects the static HTML error/maintenance pages to live under the errors_source
directory and copies them (with assets replaced for their hashed versions) to the rails root directory.
A sample maintenance page then may look like this (notice the CSS asset link and logo image - these assets are simply shared with the main rails code):
<html>
<head>
...
<link href="application.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body>
...
<a href="/"><img src="logo.png" width="161" height="61"/></a>
...
</body>
</html>