Ruby on rails 在常量之后加载控制器?

Ruby on rails 在常量之后加载控制器?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我想在UsersHelper中使用常量: CONSTANT_CONTROLLER = [["Configuration", MerchantsController], ["System", SystemStatusController]] 但由于我使用的是AuthenticatedSystem,服务器出现以下故障: undefined method `requires_role' for MerchantsController:Class 我试图包含AuthenticatedSystem,

我想在UsersHelper中使用常量:

CONSTANT_CONTROLLER =  [["Configuration", MerchantsController], ["System", SystemStatusController]]
但由于我使用的是AuthenticatedSystem,服务器出现以下故障:

undefined method `requires_role' for MerchantsController:Class
我试图包含AuthenticatedSystem,但它不起作用。当我有方法时:

def controller_display_name_to_real_name
    [["Configuration", MerchantsController], ["System", SystemStatusController]]
end
一切都好。我猜,当控制器未加载时,常量会提前加载。这是正确的吗?

请尝试以下操作

Controller.constantize

您必须输入控制器的名称。

我想您是对的。我找到的解决方案之一是只将字符串设置为常量(
'MerchantsController'
例如)。然后,当我需要使用它时(即加载所有常量时),我调用
MY_CONSTANT.constantize
。但是也许有更好的解决办法。谢谢你的回复听起来是个不错的解决办法