Created
June 7, 2014 16:57
-
-
Save janko/bf8bf4583e2f8c5b4963 to your computer and use it in GitHub Desktop.
Custom error pages in Rails
This file contains hidden or 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
module MyApp | |
class Application < Rails::Application | |
# ... | |
config.exceptions_app = self.routes | |
config.action_dispatch.rescue_responses.merge!( | |
"RDS::ResourceNotFound" => :not_found, | |
) | |
# ... | |
end | |
end |
This file contains hidden or 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
class ErrorsController < ApplicationController | |
def show | |
render status_code.to_s, status: status_code | |
end | |
private | |
def status_code | |
params[:code].to_i | |
end | |
end |
This file contains hidden or 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 :errors do | |
get ":code", to: :show, constraints: {code: /\d+/} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment