Skip to content

Restore visit previous URL stored in session #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def set_current_organization
end
end

# Store last url, this is needed for post-login redirect to whatever the
# user last visited.
# See #after_sign_in_path_for method in this class and Devise documentation:
# https://github.com/plataformatec/devise/wiki/How-To%3a-Redirect-to-a-specific-page-on-successful-sign-in-out
def store_location
# store last url - this is needed for post-login redirect to whatever the
# user last visited.
return unless request.get?
paths = ["/", "/users/sign_in", "/users/sign_up", "/users/password/new",
"/users/password/edit", "/users/confirmation", "/users/sign_out"]
Expand All @@ -45,12 +47,15 @@ def store_location
end
end

# Returns a string with the path where the user will be redirected
# after the sign in.
#
# @return [String]
def after_sign_in_path_for(user)
if user.members.present?
users_path
else
page_path("about")
end
return session[:previous_url] if session[:previous_url]
return users_path if user.members.present?

page_path("about")
end

private
Expand Down