Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting Devise After Sign Out

Tags:

What's the best practice for redirecting the user, using Devise, back to the page she is currently on after she logs out?

The devise docs say to override the following (in your application controller):

def after_sign_out_path_for(resource_or_scope)
  # logic here
end

Which is easy enough. However, I'm setting the previous page to be a session variable, like this:

session[:return_to] = request.fullpath

The problem is that when you sign out, the session is destroyed, and the top method occurs AFTER the session is destroyed, meaning you no longer have access to it. I'm thinking of putting it in a class variable or something similar, but wanted to see what SO thought.

like image 574
aronchick Avatar asked Jun 29 '11 00:06

aronchick


1 Answers

If you are always using the page where the logout link was clicked you could use the referrer on the request.

def after_sign_out_path_for(resource_or_scope)
  request.referrer
end
like image 93
Kyle d'Oliveira Avatar answered Oct 07 '22 12:10

Kyle d'Oliveira