-
-
Save tehprofessor/2695032 to your computer and use it in GitHub Desktop.
Custom error pages
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
# | |
# 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