Devise在登录或注册后重定向到原始位置? [英] Devise redirect back to the original location after sign in or sign up?
问题描述
这里我使用Devise Gem进行身份验证。如果有人想要打开页面而不登录,那么它会重定向到sign_in页面,并在登录后返回到用户尝试打开的页面。
我使用重定向循环与Devise after_sign_in_path_for 链接为我的问题,但它不适用于我。
Here I'm using Devise Gem for authentication. If someone want to open page without login then it redirect to sign_in page and after signed in it back to the page which user try to open. I use Redirect loop with Devise after_sign_in_path_for link for my problem but it does not work for me.
def after_sign_in_path_for(resource)
params[:next] || super
end
它不会将我重定向到我要打开的页面。
例如:如果我要打开127.0.0.1:3000/post/2/edit,它登录后不会返回此页面。
It doesn't redirect back me to the page which I want to open. for example: If I want to open "127.0.0.1:3000/post/2/edit", it doest not back to this page after signed in.
推荐答案
最好的资源是官方回购/维基/问题,然后是SO。你发现的答案已经过时了。
The best resource to seek is the official repo/wiki/issues, and then SO. The answer you found is out of date.
在ApplicationController中添加以下内容
Just add the following in ApplicationController
after_filter :store_location
def store_location
# store last url as long as it isn't a /users path
session[:previous_url] = request.fullpath unless request.fullpath =~ /\/users/
end
def after_sign_in_path_for(resource)
session[:previous_url] || root_path
end
这篇关于Devise在登录或注册后重定向到原始位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!