Skip to content

Instantly share code, notes, and snippets.

@bclennox
Last active December 19, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bclennox/5938283 to your computer and use it in GitHub Desktop.
Save bclennox/5938283 to your computer and use it in GitHub Desktop.
Generate static error pages from normal Rails templates.
class ErrorsController < ApplicationController
layout 'errors'
caches_page :show
def show
render action: params[:id]
end
end
namespace :maintenance do
desc 'Create static versions of our custom HTTP error pages'
task :create_error_pages => :environment do
if Rails.application.config.action_controller.perform_caching
session = ActionDispatch::Integration::Session.new(Rails.application)
%w{401 404 422 500 maintenance}.each do |error|
puts "Creating /errors/#{error}.html"
session.get("/errors/#{error}")
end
else
puts %{
** Error: config.action_controller.perform_caching is false, which means these pages wouldn't be created. Try this instead:
RAILS_ENV=production #{File.basename $0} #{ARGV.join(' ')}
}.strip_heredoc.strip
end
end
end
# ...
resources :errors, only: :show
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment