开发者

Ruby on rails: model name uninitialized error (mismatch of module)

I am accessing model Company::Item in controller Security::MyController. It is giving error uninitialised constant Security::Company::Item . So basically it is appending 'Security::' for given model. It is not the case with some other models say Security::User(mo开发者_Go百科del in same module security). What could be possible explanation for this?


This is a scope resolution problem. You should try using ::Company::Iteminside Security::MyController

According to Ruby Language Spec

::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.

Prefixing :: will prevent Ruby from applying the default scope in that context, which in your case, is the Security:: scope

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜