Last active
January 19, 2017 22:40
-
-
Save richpeck/3ec53bfe74753798a9f3c2341398a7ae to your computer and use it in GitHub Desktop.
ROUTES Exception Handling In Rails
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
# => 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 |
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
# => 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