Skip to content

Commit 31e6900

Browse files
committed
Restore visit previous URL stored in session
1 parent 394c0f6 commit 31e6900

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

app/controllers/application_controller.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def set_current_organization
3434
end
3535
end
3636

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

50+
# Returns a string with the path where the user will be redirected
51+
# after the sign in.
52+
#
53+
# @return [String]
4854
def after_sign_in_path_for(user)
49-
if user.members.present?
50-
users_path
51-
else
52-
page_path("about")
53-
end
55+
return session[:previous_url] if session[:previous_url]
56+
return users_path if user.members.present?
57+
58+
page_path("about")
5459
end
5560

5661
private

0 commit comments

Comments
 (0)