mirror of
https://github.com/jbranchaud/til
synced 2026-01-05 16:18:01 +00:00
Add Rescue From as a rails til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_353 TILs and counting..._
|
_354 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -222,6 +222,7 @@ _353 TILs and counting..._
|
|||||||
- [Migrating Up Down Up](rails/migrating-up-down-up.md)
|
- [Migrating Up Down Up](rails/migrating-up-down-up.md)
|
||||||
- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md)
|
- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md)
|
||||||
- [Pretend Generations](rails/pretend-generations.md)
|
- [Pretend Generations](rails/pretend-generations.md)
|
||||||
|
- [Rescue From](rails/rescue-from.md)
|
||||||
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
|
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
|
||||||
- [Select A Select By Selector](rails/select-a-select-by-selector.md)
|
- [Select A Select By Selector](rails/select-a-select-by-selector.md)
|
||||||
- [Select Value For SQL Counts](rails/select-value-for-sql-counts.md)
|
- [Select Value For SQL Counts](rails/select-value-for-sql-counts.md)
|
||||||
|
|||||||
21
rails/rescue-from.md
Normal file
21
rails/rescue-from.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Rescue From
|
||||||
|
|
||||||
|
The
|
||||||
|
[`rescue_from`](http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html)
|
||||||
|
method, provided by `ActiveSupport`, is a handy way to provide a catch-all
|
||||||
|
response to a particular exception.
|
||||||
|
|
||||||
|
For instance, if many of the controllers in your application raise a
|
||||||
|
`User::NotAuthorized` error for unauthorized requests, the
|
||||||
|
`ApplicationController` can provide a unified response. This will help dry
|
||||||
|
up your controllers and prevent any potential inconsistencies.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class ApplicationController < ActionController::Base
|
||||||
|
rescue_from User::NotAuthorized do |exception|
|
||||||
|
# respond with some Not Authorized page
|
||||||
|
end
|
||||||
|
|
||||||
|
...
|
||||||
|
end
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user