1

我正在访问model Company :: Item in controller Security :: MyController。它给出的错误未初始化的常量Security :: Company :: Item。所以基本上它为给定的模型附加'Security ::'。一些其他模型并不是这样说Security :: User(在相同的模块安全模型中)。对此有什么可能的解释?Ruby on rails:型号名称未初始化错误(模块不匹配)

+0

应用默认范围请发布有问题的代码 – jschorr

回答

2

这是一个范围解决问题。你应该尝试使用::Company::ItemSecurity::MyController

根据Ruby语言规格

::Something is a shortcut for Object::Something. The idea is that ::Something 
should look up a constant called Something in the global scope, but since ruby 
doesn't truly have a global scope, it looks it up in the Object class, which is 
the nearest thing in ruby to a global scope. 

,前缀::将防止从红宝石在这方面,它在你的情况,是Security::范围

+0

非常感谢 –

相关问题