Skip to content

Instantly share code, notes, and snippets.

@danivovich
Last active December 11, 2015 17:49
Show Gist options
  • Save danivovich/4637537 to your computer and use it in GitHub Desktop.
Save danivovich/4637537 to your computer and use it in GitHub Desktop.
replace links to assets in static error pages with links to hashed asset pipeline assets
namespace :assets do
desc 'Update the URIs for assets used in the static pages (e.g. 500.html)'
task :update_static_pages => :environment do
manifest_path = Rails.root.join('public', 'assets', 'manifest.yml')
unless File.exists?(manifest_path.to_s)
raise "Must run assets:precompile first"
end
manifest = YAML.load(manifest_path.read)
%w[404 422 500 504 browser].each do |static_page|
path = Rails.root.join('public', "#{static_page}.html")
content = path.read
manifest.each_pair do |base_value, hash_value|
content.gsub!(base_value, hash_value)
end
File.open(path, 'w') do |file|
file.write content
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment