Last Updated: February 25, 2016
·
857
· neutralino1

Custom Rails error pages

In ApplicationController :

unless Rails.application.config.consider_all_requests_local
  rescue_from Exception, with: lambda { |exception| render_error 500, exception }
  rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end

private

def render_error(status, exception)
  render template: "errors/error_#{status}", layout: 'layouts/application', status: status
end

2 Responses
Add your response

Consider using exceptions_app to also handle exceptions in the middleware layer with a custom error page https://coderwall.com/p/w3ghqq

over 1 year ago ·

@jeroenr Thank you for that tip, I was looking for that exactly ;)

over 1 year ago ·