页面没有正确地重定向Ruby on Rails

出于某种原因,我在点击页面的受保护部分时收到错误:

Firefox:页面未正确重定向

这是我在ApplicationController使用的方法:

 protected def authorize unless User.find_by_id(session[:remember_token]) flash[:notice] = "Please Log in" redirect_to :controller => 'sessions', :action => 'new' end end 

出于某种原因,我无法访问sessions/new ,这是我的登录页面。 任何帮助将非常感谢。 我检查了路线,我得到了sessions/new

作为一个受过良好教育的猜测,我会说你有这个:

 before_filter :authorize 

哪个会继续重定向到自己。

你可以通过只传递你想要的那个来解决这个问题:

 before_filter :authorize, :only => [:action_a, :action_b] 

或者指定你不想要的那些(如果你只想停止你的会话,可能更可取#新动作

 before_filter :authorize, :except => [:new, :create] 

如果在inheritance的控制器上指定了before_filter(例如,你的SessionsController从ApplicationControllerinheritance了before_filter),那么你可以使用skip_before_filter

 skip_before_filter :authorize, :only => [:new, :create] 

我有一个类似的问题,这种情况发生的主要原因是我们重定向到自己。 确保你没有将before_action / before_filter应用于Session#new

 before_filter :authorize, :except => [:new, :create]