From 80295d44c9d023ecf32f6f37f2a8008c2ef0f06d Mon Sep 17 00:00:00 2001 From: Alex Emelyanov Date: Fri, 17 Jan 2020 23:05:40 +0800 Subject: [PATCH] Fix issue in README for multiple error messages --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0da14f5..ee747394 100644 --- a/README.md +++ b/README.md @@ -563,8 +563,14 @@ end Then you can get this error message in exception handler: ```ruby rescue_from Pundit::NotAuthorizedError do |e| - message = e.reason ? I18n.t("pundit.errors.#{e.reason}") : e.message - flash[:error] = message, scope: "pundit", default: :default + message = + if e.reason + I18n.t("pundit.errors.#{e.reason}", scope: "pundit", default: :default) + else + e.message + end + + flash[:error] = message redirect_to(request.referrer || root_path) end ```