2013-03-22 116 views
0

我想有恒定UsersHelper:控制器在常量之后加载?

CONSTANT_CONTROLLER = [["Configuration", MerchantsController], ["System", SystemStatusController]] 

但自从我使用AuthenticatedSystem服务器failes有:

undefined method `requires_role' for MerchantsController:Class 

我想包括AuthenticatedSystem但它并没有奏效。当我有方法:

def controller_display_name_to_real_name 
    [["Configuration", MerchantsController], ["System", SystemStatusController]] 
end 

一切都OK。我猜这些常量是在控制器没有加载时提前加载的。这是正确的吗?

+1

我认为你是对的。我发现的一个解决方案是只将字符串设置为常量(例如“MerchantsController”)。然后,当我需要使用它时(即,当所有常量都被加载时),我称之为“MY_CONSTANT.constantize”。但也许有更好的解决方案。 – pierallard 2013-03-22 11:57:50

+0

感谢您的回应听起来像一个很好的解决方案 – 2013-03-22 12:13:33

回答

0

尝试如下

Controller.constantize 

你必须constantize控制器的名字。