[英]Rails - Redirect_to error in controller - “The page isn't redirecting properly” "
[英]Page isn't redirecting properly 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]
如果在繼承的控制器上指定了before_filter(例如,你的SessionsController從ApplicationController繼承了before_filter),那么你可以使用skip_before_filter
skip_before_filter :authorize, :only => [:new, :create]
我有一個類似的問題,這種情況發生的主要原因是我們重定向到自己。 確保你沒有將before_action / before_filter應用於Session#new
before_filter :authorize, :except => [:new, :create]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.