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.
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
if you want to redirect user to sign in page after sign out write the below function in you application controller
def after_sign_out_path_for(resource_or_scope)
new_user_session_path
end
精彩评论