The guide Asset Pipeline Error Pages now no longer works, since non-digest assets aren't generated in newer Rails apps. To fix this, I've replaced the config/initializers/exceptions.rb
initializer that swaps out the middleware with the Rake task here, which will be run after Rails assets:precompile
task.
Created
September 10, 2014 06:51
-
-
Save tylerhunt/c93d26673e25c0474ef2 to your computer and use it in GitHub Desktop.
Static error pages from dynamically generated 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 | |
task :precompile do | |
# copy generated HTML error pages into public path after asset generation | |
%w(404.html 422.html 500.html).each do |file| | |
asset_file = ActionController::Base.helpers.asset_digest_path(file) | |
asset_path = Rails.public_path.join('assets', asset_file) | |
public_path = Rails.public_path.join(file) | |
cp asset_path, public_path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice approach, too.
I've taken the base idea but used a different approach:
Rails 5+ has the ApplicationController.renderer, which can render any template at any time. This works better than the Asset Pipeline, because the view works almost exactly the same. I've build a small gem, that wraps that:
https://rubygems.org/gems/static_error_pages