登录后重定向到原始任务 [英] Redirecting after a login to the original task
问题描述
所以我想发送电子邮件给用户一些链接,您可以点击进行操作,但如果用户尚未登录,我希望能够让用户登录,然后重定向他回到他想要的东西。
So I want to send emails to users with some links which you can click on to do things, but if the user isn't already logged in, I'd like to be able to let the user log in and then redirect him back to what he was trying to get to.
我在application_controller.rb中有这些方法
I have these methods in application_controller.rb
这个在URL链接到的地方被称为before_filter,捕获用户不应该在任何地方尝试去存储意图
This is called as a before_filter on the place the URL links to, catches that the user shouldn't be wherever he is trying to go and stores the intent
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
他应该抓住他,然后他回到他所属的地方。
And this should catch him after he signs in and put him back where he belongs.
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
但是它没有。相反,我得到一个非常讨厌的不能重定向到零!如果我将它读入一个局部变量并将其存储起来,更多的东西就会崩溃。我非常困惑,这是一个非常常见的事情想要做的。
However, it does not. Instead I get a very nasty "cannot redirect to nil!" If I read it into a local variable and store it, even more things break. I am very baffled, this has to be an extremely common thing to want to do.
推荐答案
我想要让用户
登录,然后将他重定向到
他想要的东西。
I'd like to be able to let the user log in and then redirect him back to what he was trying to get to.
此行为已由Devise的 authenticate_user!
before_filter提供。因为你的devise标签在这个故事和使用 user_signed_in?
表明你已经在使用Devise为什么重新发明自己的解决方案?
This behavior is already provided by Devise's authenticate_user!
before_filter. Since your "devise" tag on this story and use of user_signed_in?
suggest that you are already using Devise why reinvent your own solution?
这篇关于登录后重定向到原始任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!