Skip to content

Instantly share code, notes, and snippets.

@corny
Created May 12, 2012 11:32
Show Gist options
  • Save corny/2666010 to your computer and use it in GitHub Desktop.
Save corny/2666010 to your computer and use it in GitHub Desktop.
Custom error pages
#
# Usage:
# class ApplicationController < ActionController::Base
# include ErrorPages
# end
#
module ErrorPages
extend ActiveSupport::Concern
included do
unless Magistrix::Application.config.consider_all_requests_local
rescue_from ActionController::RoutingError, with: :render_404
rescue_from ActionController::UnknownController, with: :render_404
rescue_from ActionController::UnknownHttpMethod, with: :render_404
rescue_from AbstractController::ActionNotFound, with: :render_404
rescue_from ActiveRecord::RecordNotFound, with: :render_404
end
end
private
def render_404(exception)
# send exception to newrelic
newrelic_notice_error(exception) if respond_to?(:newrelic_notice_error)
@not_found_path = exception.message
respond_to do |format|
format.html { render template: 'errors/not_found', layout: 'layouts/application', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment