所以我想向用户发送电子邮件,其中包含一些链接,您可以单击这些链接来执行操作,但如果用户尚未登录,我希望能够让用户登录然后重定向他回到了他想要达到的目标。
我在 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
然而,事实并非如此。相反,我得到了一个非常令人讨厌的“无法重定向到零!”如果我将其读入局部变量并将其存储,则会出现更多问题。我很困惑,这一定是一件非常常见的事情。
最佳答案
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,为什么要重新发明自己的解决方案呢?
关于ruby-on-rails - 登录后重定向到原始任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5359195/