Skip to content

Instantly share code, notes, and snippets.

@tehprofessor
Forked from corny/error_pages.rb
Created May 14, 2012 16:53
Show Gist options
  • Save tehprofessor/2695032 to your computer and use it in GitHub Desktop.
Save tehprofessor/2695032 to your computer and use it in GitHub Desktop.
Custom error pages
#
# Usage:
# class ApplicationController < ActionController::Base
# include ErrorPages
# end
#
require 'active_support/core_ext/array/extract_options'
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, *args)
# send exception to newrelic
options = args.extract_options!
newrelic_notice_error(exception, options) 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