我想設置一些內容,如果我的應用程序中的帳戶被禁用,我希望所有請求都被重定向到「禁用」消息。如何在所有請求上實現重定向(在某些情況下)?
我在我的ApplicationController此設置:
class ApplicationController < ActionController::Base
before_filter :check_account
def check_account
redirect_to :controller => "main", :action => "disabled" and return if !$account.active?
end
end
當然,因爲它進入一個無限循環,如果賬戶沒有激活這完全不是那麼回事。我希望能使用類似:
redirect_to :controller => "main", :action => "disabled" and return if !$account.active? && @controller.controller_name != "main" && @controller.action_name != "disabled"
,但我注意到,在Rails的2.1版(我使用的是什麼),@Controller現在控制器,這似乎並沒有在ApplicationController的工作。
什麼是最好的方式來實現這樣的事情?
我認爲這可能是最簡潔的方式來實現它。謝謝! – 2008-09-18 07:12:41