Sitemap
šŸ’Ž Ruby on Rails Web Application Development šŸ’Ž

Tutorials for Ruby on Rails

šŸ”‹ Custom (400 / 500) Error Pages in Ruby on Rails → Exception Handler

12 min readJan 20, 2017

--

ExceptionHandler is our Rails custom error pages gem…
šŸ“¹ Introductory video about how create custom 400/500 error pages in Ruby on Rails… šŸ“¹

šŸ“‹ Overview

Rails default error pages…
The structure of an HTTP response…
Some of our Custom Error Pages in Rails…

ā˜‘ļø How It Works

Rails’ Default error pages are kept in the ./public folder…
Rails’ middleware stack…

āœ… Overview

āš”ļø Gem (Exception Handler)

ExceptionHandler is the most popular rails custom error pages gem…
ExceptionHandler on RubyGems

🚦 HTTP Status Codes

Great video about HTTP Status Codes
Full list of HTTP Status Codes…
HTTP Headers & Message Body…

šŸ’£ Exceptions

# config/application.rb
config.action_dispatch.rescue_responses.merge!(
"YourCustomErrorClass" => :not_found
)

āœ”ļø Manual Implementations

šŸ Routes

# config/application.rb
config.exceptions_app = self.routes
# config/routes.rb
%w( 404 422 500 ).each do |code|
get code, controller: :application, action: :error, code: code
end
# app/controllers/application_controller.rb
def error
render status_code.to_s, status: (params[:code] || 500)
end
# app/views/application/404.html.erb
# stuff here

šŸ“ Controller

# config/application.rb
config.exceptions_app = ->(env) { ExceptionsController.action(:show).call(env)}
# app/controllers/exceptions_controller.rb
def show
# Specific code
end
# app/views/exceptions/show.html.erb
@exception.description

āš”ļø Gem

šŸ“Thanks for reading

--

--

Responses (4)