我想设置一些内容,如果我的应用程序中的帐户被禁用,我希望所有请求都被重定向到“禁用”消息。如何在所有请求上实现重定向(在某些情况下)?
我在我的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