Top*_*hef 2 redirect 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
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我无法访问sessions/new,这是我的登录页面.任何帮助将非常感谢.我检查了路线,我得到了sessions/new.
作为一个受过良好教育的猜测,我会说你有这个:
before_filter :authorize
Run Code Online (Sandbox Code Playgroud)
哪个会继续重定向到自己.
你可以通过只传递你想要的那个来解决这个问题:
before_filter :authorize, :only => [:action_a, :action_b]
Run Code Online (Sandbox Code Playgroud)
或者指定你不想要的那些(如果你只想停止你的会话,可能更可取#新动作
before_filter :authorize, :except => [:new, :create]
Run Code Online (Sandbox Code Playgroud)
如果在继承的控制器上指定了before_filter(例如,你的SessionsController从ApplicationController继承了before_filter),那么你可以使用skip_before_filter
skip_before_filter :authorize, :only => [:new, :create]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3219 次 |
| 最近记录: |