From 202767765b24d1d8cafd54840fe8f9db77790632 Mon Sep 17 00:00:00 2001 From: Duncan Stuart Date: Fri, 1 Apr 2022 11:42:47 +0200 Subject: [PATCH] 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:(https://github.com/rails/rails/blob/de53ba56cab69fb9707785a397a59ac4aaee9d6f/actionpack/lib/action_controller/metal/redirecting.rb#L95-L128) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25c2463..0f242fb 100644 --- a/README.md +++ b/README.md @@ -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 ```