After successfully logging in through Devise, how can I redirect the user to the page they were on?
I already read and searched a lot, and I understand that I need to define after_sign_in_path_for
. I did this and it works correctly, what I came across, understands how the previous page is stored, and how to properly name it.
I have this in the session controller:
def after_sign_in_path_for(resource) return request.env['omniauth.origin'] || session[:user_return_to] || root_path end
I also tried
... return request.env['omniauth.origin'] || stored_location_for(resource) || root_path ...
I donβt think I understand how to save the location, since the user is redirected back to the root path if he clicks to enter.
A sign can be initiated in two ways. Either (a) the user tries to access the restricted view (i.e. before_filter :authenticate_user!...
, in which case they are redirected and requested to enter the system. Or (b) the user clicks the link for the character that is available on each page if the user is not logged in.
(a) seems to work. (b) no. I think I need to save the current location to the session when the user clicks the login link.
How can I do it? Or, where is a good source of information that will help me figure this out.
Thanks!
source share