Module: TurboGraft::XHRHeaders

Extended by:
ActiveSupport::Concern
Defined in:
lib/turbograft/xhr_headers.rb

Overview

Intercepts calls to _compute_redirect_to_location (used by redirect_to) for two purposes.

  1. Corrects the behavior of redirect_to with the :back option by using the X-XHR-Referer

request header instead of the standard Referer request header.

  1. Stores the return value (the redirect target url) to persist through to the redirect

request, where it will be used to set the X-XHR-Redirected-To response header. The Turbolinks script will detect the header and use replaceState to reflect the redirected url.

Instance Method Summary collapse

Instance Method Details

#_compute_redirect_to_location(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/turbograft/xhr_headers.rb', line 15

def _compute_redirect_to_location(*args)
  options, request = _normalize_redirect_params(args)

  store_for_turbolinks begin
    if options == :back && request.headers["X-XHR-Referer"]
      super(*[(request if args.length == 2), request.headers["X-XHR-Referer"]].compact)
    else
      super(*args)
    end
  end
end