instance method redirect_back

Ruby on Rails 5.0.7.2

Since v5.0.7.2

Available in: v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

redirect_back(fallback_location:, **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:  articles_url
redirect_back fallback_location:  proc { edit_post_url(@post) }

All options that can be passed to redirect_to are accepted as options and the behavior is identical.

Parameters

fallback_location keyreq
args keyrest
Source
# File actionpack/lib/action_controller/metal/redirecting.rb, line 88
    def redirect_back(fallback_location:, **args)
      if referer = request.headers["Referer"]
        redirect_to referer, **args
      else
        redirect_to fallback_location, **args
      end
    end

Defined in actionpack/lib/action_controller/metal/redirecting.rb line 88 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Redirecting

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close