# module Turbolinks::Redirection

### Public Instance Methods

redirect_to(url = {}, options = {}) click to toggle source
Calls superclass method

    # File lib/turbolinks/redirection.rb, line 9
    def redirect_to(url = {}, options = {})
      turbolinks = options.delete(:turbolinks)

      super.tap do
        if turbolinks != false && request.xhr? && !request.get?
          visit_location_with_turbolinks(location, turbolinks)
        else
          if request.headers["Turbolinks-Referrer"]
            store_turbolinks_location_in_session(location)
          end
        end
      end
    end

### Private Instance Methods

set_turbolinks_location_header_from_session() click to toggle source

    # File lib/turbolinks/redirection.rb, line 42
    def set_turbolinks_location_header_from_session
      if session && session[:_turbolinks_location]
        response.headers["Turbolinks-Location"] = session.delete(:_turbolinks_location)
      end
    end

store_turbolinks_location_in_session(location) click to toggle source

    # File lib/turbolinks/redirection.rb, line 38
    def store_turbolinks_location_in_session(location)
      session[:_turbolinks_location] = location if session
    end

visit_location_with_turbolinks(location, action) click to toggle source

    # File lib/turbolinks/redirection.rb, line 24
    def visit_location_with_turbolinks(location, action)
      visit_options = {
        action: action.to_s == "advance" ? action : "replace"
      }

      script = []
      script << "Turbolinks.clearCache()"
      script << "Turbolinks.visit(#{location.to_json}, #{visit_options.to_json})"

      self.status = 200
      self.response_body = script.join("\n")
      response.content_type = "text/javascript"
    end