页面未正确重定向 Ruby on Rails [英] Page isn't redirecting properly Ruby on Rails

查看:32
本文介绍了页面未正确重定向 Ruby on Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For some reason, I am getting an error when clicking on a protected part of my page:

Firefox:页面没有正确重定向

Firefox: The page isn't redirecting properly

这是我在 ApplicationController 中使用的方法:

Here is the method I use in my 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.

For some reason, I am not getting access to sessions/new, which is my login page. Any help would be very much appreciated. I checked routes and I have get sessions/new.

推荐答案

作为一个有根据的猜测,我会说你有这个:

As a well educated guess, I'd say you have this:

before_filter :authorize

哪个会一直重定向到自己.

Which will keep redirecting to itself.

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

You can fix this either by passing only the ones you want:

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

或者指定您不想要的(如果您只想停止会话,可能更可取#new action

Or specify the ones you don't want (probably preferable if you only want to stop your sessions#new action

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

如果您的 before_filter 是在继承的控制器上指定的(例如,您的 SessionsController 从 ApplicationController 继承 before_filter),那么您可以使用 skip_before_filter

If your before_filter is specified on an inherited controller (e.g. your SessionsController is inheriting the before_filter from ApplicationController) then you can use skip_before_filter

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

这篇关于页面未正确重定向 Ruby on Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆