登录原始任务后重定向

所以我想向用户发送电子邮件,其中包含一些链接,您可以单击这些链接来执行操作,但如果用户尚未登录,我希望能够让用户登录,然后将其重定向回他试图去做什么。

我在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!已经提供了这种行为authenticate_user! 的before_filter。 既然你对这个故事的“设计”标签和user_signed_in?使用user_signed_in? 建议你已经在使用Devise为什么要重新发明你自己的解决方案?