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

Use redirect_back in README (#732)

Inspired by https://github.com/varvet/pundit/issues/727
Thanks to @joemasilotti 

Since Rails 5 (?) we have a more idiomatic way to redirect back to the previous page.

As it turns out this is pretty much just syntactic sugar for the previous implementation, but it feels like the more correct way to do it these days:(de53ba56ca/actionpack/lib/action_controller/metal/redirecting.rb (L95-L128))
This commit is contained in:
Duncan Stuart 2022-04-01 11:42:47 +02:00 committed by GitHub
parent 74536478d6
commit 202767765b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -512,7 +512,7 @@ class ApplicationController < ActionController::Base
def user_not_authorized
flash[:alert] = "You are not authorized to perform this action."
redirect_to(request.referrer || root_path)
redirect_back(fallback_location: root_path)
end
end
```
@ -541,7 +541,7 @@ class ApplicationController < ActionController::Base
policy_name = exception.policy.class.to_s.underscore
flash[:error] = t "#{policy_name}.#{exception.query}", scope: "pundit", default: :default
redirect_to(request.referrer || root_path)
redirect_back(fallback_url: root_path)
end
end
```