Skip to content

Commit

Permalink
Fixed using I18n.t in README for multiple error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
holyketzer committed Jan 18, 2020
1 parent 80295d4 commit f3c0c15
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ class ProjectPolicy < ApplicationPolicy
def create?
if user.has_paid_subscription?
if user.project_limit_reached?
raise Pundit::NotAuthorizedError, reason: 'user.project_limit_reached'
raise Pundit::NotAuthorizedError, reason: 'user.project_limit_reached', record: user, query: :create
else
true
end
Expand All @@ -563,14 +563,7 @@ end
Then you can get this error message in exception handler:
```ruby
rescue_from Pundit::NotAuthorizedError do |e|
message =
if e.reason
I18n.t("pundit.errors.#{e.reason}", scope: "pundit", default: :default)
else
e.message
end
flash[:error] = message
flash[:error] = I18n.t("errors.#{e.reason}", scope: "pundit", default: e.message)
redirect_to(request.referrer || root_path)
end
```
Expand Down

0 comments on commit f3c0c15

Please sign in to comment.