Skip to content

Instantly share code, notes, and snippets.

@janko
Created June 7, 2014 16:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janko/bf8bf4583e2f8c5b4963 to your computer and use it in GitHub Desktop.
Save janko/bf8bf4583e2f8c5b4963 to your computer and use it in GitHub Desktop.
Custom error pages in Rails
module MyApp
class Application < Rails::Application
# ...
config.exceptions_app = self.routes
config.action_dispatch.rescue_responses.merge!(
"RDS::ResourceNotFound" => :not_found,
)
# ...
end
end
class ErrorsController < ApplicationController
def show
render status_code.to_s, status: status_code
end
private
def status_code
params[:code].to_i
end
end
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