[英]Redirecting after a login to the original task
因此,我想通过一些链接向用户发送电子邮件,您可以单击这些链接来执行操作,但是如果该用户尚未登录,我希望能够让该用户登录,然后将其重定向回他想要达到的目标。
我在application_controller.rb中有这些方法
这称为URL链接到的位置上的before_filter,它捕获到用户不应在他要去的任何地方并存储意图
def user_in_beta
unless user_signed_in? && current_user.beta
if user_signed_in?
redirect_to :home_betawait
else
session[:original_uri] = request.request_uri
redirect_to new_user_session_path
end
end
end
这应该在他登录后抓住他并将其放回原处。
def after_sign_in_path_for(resource_or_scope)
if current_user.beta
if session[:original_uri].nil?
:home_index
else
session[:original_uri]
end
else :home_betawait
end
end
但是,事实并非如此。 相反,我得到一个非常讨厌的“无法重定向到零!” 如果我将其读入局部变量并将其存储,则会发生更多故障。 我感到非常困惑,这必须是一件非常普通的事情。
我希望能够让用户登录,然后将其重定向回他尝试访问的位置。
这种行为已经由Devise的authenticate_user!
的before_filter。 既然您在这个故事中使用了“ user_signed_in?
”标签,并且使用了user_signed_in?
建议您已经在使用Devise,为什么要重新发明自己的解决方案?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.