aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorMauro George <maurogot@gmail.com>2014-06-19 10:13:25 -0300
committerMauro George <maurogot@gmail.com>2014-06-19 10:57:14 -0300
commit32e83e7d8d5a9e576c00153edfc6c092e1b50e38 (patch)
treed52adf25f38e53e6ac69034ce840889d344a7fbd /guides
parent96f28b6a9899889c5b9d1786ca155e0c97abae7a (diff)
downloadrails-32e83e7d8d5a9e576c00153edfc6c092e1b50e38.tar.gz
rails-32e83e7d8d5a9e576c00153edfc6c092e1b50e38.tar.bz2
rails-32e83e7d8d5a9e576c00153edfc6c092e1b50e38.zip
Create custom errors page on ActionController guides
[ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/action_controller_overview.md55
1 files changed, 55 insertions, 0 deletions
diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md
index 3d15319ca4..0d1bd2061d 100644
--- a/guides/source/action_controller_overview.md
+++ b/guides/source/action_controller_overview.md
@@ -1166,6 +1166,61 @@ end
NOTE: Certain exceptions are only rescuable from the `ApplicationController` class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's [article](http://m.onkey.org/2008/7/20/rescue-from-dispatching) on the subject for more information.
+
+### Custom errors page
+
+You can customize the layout of your error handling using controllers and views.
+First define your app own routes to display the errors page.
+
+* `config/application.rb`
+
+ ```ruby
+ config.exceptions_app = self.routes
+ ```
+
+* `config/routes.rb`
+
+ ```ruby
+ get '/404', to: 'errors#not_found'
+ get '/422', to: 'errors#unprocessable_entity'
+ get '/500', to: 'errors#server_error'
+ ```
+
+Create the controller and views.
+
+* `app/controllers/errors_controller.rb`
+
+ ```ruby
+ class ErrorsController < ApplicationController
+ layout 'error'
+
+ def not_found
+ render status: :not_found
+ end
+
+ def unprocessable_entity
+ render status: :unprocessable_entity
+ end
+
+ def server_error
+ render status: :server_error
+ end
+ end
+ ```
+
+* `app/views`
+
+ ```
+ errors/
+ not_found.html.erb
+ unprocessable_entity.html.erb
+ server_error.html.erb
+ layouts/
+ error.html.erb
+ ```
+
+Do not forget to set the correct status code on the controller as shown before. You should avoid using the database or any complex operations because the user is already on the error page. Generating another error while on an error page could cause issues.
+
Force HTTPS protocol
--------------------