2011-12-09 40 views
2

出於某種原因,正確地重定向紅寶石,我讓我的網頁的一個保護區,當點擊了錯誤:頁面沒有on Rails的

Firefox: The page isn't redirecting properly

下面是我在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

+0

你在日誌裏有什麼? – apneadiving

回答

9

作爲一個受過良好教育的猜測,我會說你有這樣的:

before_filter :authorize 

這將讓重定向到自身。

您可以通過只透過那些你想解決這個問題:

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

或指定您不希望那些(可能是最好,如果你只是想阻止你的會話#新動作

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

如果繼承的控制器上指定您的before_filter(例如,您的SessionsController是繼承自ApplicationController中的的before_filter),那麼你可以使用skip_before_filter

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

聽起來不錯,+1 – apneadiving

+0

我確實被重定向到sessions/new,但頁面沒有加載,並且出現錯誤。以下是錯誤的詳細信息:「Firefox已經檢測到服務器以永遠不會完成的方式重定向該地址的請求。」 – TopChef

+1

@TopChef是的,這聽起來像是一個重定向到自己的經典案例。如果我的修復無效,請提供您的ApplicationController和SessionsController。 – Gazler

0

我有類似的問題,這種情況發生的主要原因是當我們重定向到自己。確保你沒有應用before_action/before_filter到Session#new

before_filter :authorize, :except => [:new, :create] 
相關問題