Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 页码为';t正确重定向Ruby on Rails_Ruby On Rails_Redirect - Fatal编程技术网

Ruby on rails 页码为';t正确重定向Ruby on Rails

Ruby on rails 页码为';t正确重定向Ruby on Rails,ruby-on-rails,redirect,Ruby On Rails,Redirect,由于某些原因,我在单击页面的受保护部分时出错: Firefox:页面没有正确重定向 以下是我在应用程序控制器中使用的方法: protected def authorize unless User.find_by_id(session[:remember_token]) flash[:notice] = "Please Log in" redirect_to :controller => 'sessions', :action => 'new'

由于某些原因,我在单击页面的受保护部分时出错:

Firefox:页面没有正确重定向

以下是我在
应用程序控制器中使用的方法:

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

由于某些原因,我无法访问
会话/new
,这是我的登录页面。任何帮助都将不胜感激。我检查了路线,得到了
sessions/new

作为一个受过良好教育的猜测,我想你有以下几点:

before_filter :authorize
它将继续重定向到自身

您可以通过只传递所需内容来解决此问题:

before_filter :authorize, :only => [:action_a, :action_b]
或者指定您不想要的(如果您只想停止会话,可能更可取)新操作

before_filter :authorize, :except => [:new, :create]
如果在继承的控制器上指定了before_筛选器(例如,SessionController从ApplicationController继承before_筛选器),则可以使用skip_before_筛选器

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

我也遇到过类似的问题,发生这种情况的主要原因是当我们重定向到自身时。请确保您没有将before_action/before_筛选器应用到
会话#new

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

你的日志中有什么?我确实被重定向到sessions/new,但是页面没有加载,我收到了错误。下面是错误的详细信息:“Firefox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求。”@TopChef是的,这听起来像是一个典型的重定向到自身的案例。如果我的修复没有帮助,请提供您的应用程序控制器和会话控制器。