module Devise::Controllers::StoreLocation
def add_fragment_back_to_path(uri, path)
def add_fragment_back_to_path(uri, path) [path, uri.fragment].compact.join('#') end
def extract_path_from_location(location)
def extract_path_from_location(location) uri = parse_uri(location) if uri path = remove_domain_from_uri(uri) path = add_fragment_back_to_path(uri, path) path end end
def parse_uri(location)
def parse_uri(location) location && URI.parse(location) rescue URI::InvalidURIError nil end
def remove_domain_from_uri(uri)
def remove_domain_from_uri(uri) [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?') end
def store_location_for(resource_or_scope, location)
redirect_to user_facebook_omniauth_authorize_path
store_location_for(:user, dashboard_path)
Example:
Useful in combination with the `stored_location_for` helper.
Stores the provided location to redirect the user after signing in.
def store_location_for(resource_or_scope, location) session_key = stored_location_key_for(resource_or_scope) path = extract_path_from_location(location) session[session_key] = path if path end
def stored_location_for(resource_or_scope)
redirect_to stored_location_for(:user) || root_path
Example:
the given scope. Useful for giving redirect backs after sign up:
Returns and delete (if it's navigational format) the url stored in the session for
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
def stored_location_key_for(resource_or_scope)
def stored_location_key_for(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) "#{scope}_return_to" end