instance method
redirect_back
Ruby on Rails 6.1.7.10
Since v5.2.8.1Signature
redirect_back(fallback_location:, allow_other_host: true, **args)
Redirects the browser to the page that issued the request (the referrer) if possible, otherwise redirects to the provided default fallback location.
The referrer information is pulled from the HTTP Referer (sic) header on the request. This is an optional header and its presence on the request is subject to browser security settings and user preferences. If the request is missing this header, the fallback_location will be used.
redirect_back fallback_location: { action: "show", id: 5 } redirect_back fallback_location: @post redirect_back fallback_location: "http://www.rubyonrails.org" redirect_back fallback_location: "/images/screenshot.jpg" redirect_back fallback_location: posts_url redirect_back fallback_location: proc { edit_post_url(@post) } redirect_back fallback_location: '/', allow_other_host: false
Options
-
:fallback_location- The default fallback location that will be used on missingRefererheader. -
:allow_other_host- Allow or disallow redirection to the host that is different to the current host, defaults to true.
All other options that can be passed to #redirect_to are accepted as options and the behavior is identical.
Parameters
-
fallback_locationkeyreq -
allow_other_hostkey = true -
argskeyrest
Source
# File actionpack/lib/action_controller/metal/redirecting.rb, line 98
def redirect_back(fallback_location:, allow_other_host: true, **args)
referer = request.headers["Referer"]
redirect_to_referer = referer && (allow_other_host || _url_host_allowed?(referer))
redirect_to redirect_to_referer ? referer : fallback_location, **args
end
Defined in actionpack/lib/action_controller/metal/redirecting.rb line 98
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Redirecting