我想进行一些设置,以便如果我的应用程序中的帐户被禁用,我希望所有请求都被重定向到“禁用”消息。
我已经在我的 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 v2.1(我正在使用的)中,@controller 现在是控制器,这在 ApplicationController 中似乎不起作用。
实现这样的事情的最佳方法是什么?