ui4feg
Last Updated: February 25, 2016
·
441
· neutralino1
981494 10151466984546915 1613396205 o

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
Say Thanks
Respond

2 Responses
Add your response

3358
Dsc 0061

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 ·
3359
981494 10151466984546915 1613396205 o

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

over 1 year ago ·