1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

Update README's Rescuing section

I thought it worth mentioning this alternate approach to handling Pundit's NotAuthorized exception. With this approach the exception is handled by rails and the appropriate 403.html or dynamic generated error page is served.
This commit is contained in:
Andy Koch 2016-01-28 12:25:35 -08:00
parent 93500247a7
commit 1f0b739891

View file

@ -402,6 +402,10 @@ class ApplicationController < ActionController::Base
end
```
Alternatively, you can globally handle Pundit::NotAuthorizedError's by having rails handle them as a 403 error and serving a 403 error page. Add the following to application.rb:
```config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :forbidden```
## Creating custom error messages
`NotAuthorizedError`s provide information on what query (e.g. `:create?`), what