Last active
December 11, 2015 17:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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