Skip to content

Instantly share code, notes, and snippets.

@richpeck
Last active January 19, 2017 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richpeck/3ec53bfe74753798a9f3c2341398a7ae to your computer and use it in GitHub Desktop.
Save richpeck/3ec53bfe74753798a9f3c2341398a7ae to your computer and use it in GitHub Desktop.
ROUTES Exception Handling In Rails
# => Exceptions App
# => Sends to routes (notice how it does not persist the request)
# => config/application.rb
config.exceptions_app = self.routes
# => Routes
# => Sends to the appropriate view
# => config/rtoutes.rb
%w( 404 422 500 ).each do |code|
get code, controller: :application, action: :show, code: code
end
# => Controller
# => Invokes file for the error code
# => app/controllers/application_controller.rb
class ApplicationController < ApplicationController
def error
render status_code.to_s, status: (params[:code] || 500)
end
end
# => View
# => Shows different error messages
# => app/views/application/404.html.erb
Put what you want here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment