From 1f0b739891192e2ac8fd934cc27d9c1abe9233ff Mon Sep 17 00:00:00 2001 From: Andy Koch Date: Thu, 28 Jan 2016 12:25:35 -0800 Subject: [PATCH] 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. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e3208ec..f9eec5a 100644 --- a/README.md +++ b/README.md @@ -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