Module: Devise::Controllers::StoreLocation

Included in:
Helpers, FailureApp
Defined in:
lib/devise/controllers/store_location.rb

Overview

Provide the ability to store a location. Used to redirect back to a desired path after sign in. Included by default in all controllers.

Instance Method Summary collapse

Instance Method Details

#store_location_for(resource_or_scope, location) ⇒ Object

Stores the provided location to redirect the user after signing in. Useful in combination with the ‘stored_location_for` helper.

Example:

store_location_for(:user, dashboard_path)
redirect_to user_facebook_omniauth_authorize_path


34
35
36
37
38
39
40
41
42
# File 'lib/devise/controllers/store_location.rb', line 34

def store_location_for(resource_or_scope, location)
  session_key = stored_location_key_for(resource_or_scope)
  uri = parse_uri(location)
  if uri
    path = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?')
    path = [path, uri.fragment].compact.join('#')
    session[session_key] = path
  end
end

#stored_location_for(resource_or_scope) ⇒ Object

Returns and delete (if it’s navigational format) the url stored in the session for the given scope. Useful for giving redirect backs after sign up:

Example:

redirect_to stored_location_for(:user) || root_path


16
17
18
19
20
21
22
23
24
# File 'lib/devise/controllers/store_location.rb', line 16

def stored_location_for(resource_or_scope)
  session_key = stored_location_key_for(resource_or_scope)

  if is_navigational_format?
    session.delete(session_key)
  else
    session[session_key]
  end
end