我有一个命名空间路由,这是我创建控制器的方式:
module A
module B
module Test
class DummyController < ApplicationController
def quantify_stocks
something = Test::Dummy::Something.new(params)
# more code here
end
end
end
end
end
我正在尝试访问类Test::Dummy::Something
,但是它会自动使用A和B(A::B::Test
)加载常量Test?
我得到的错误是:
NameError (uninitialized constant A::B::Test::Dummy)
答案 0 :(得分:4)
尝试::Test::Dummy::Something
Test
在此上下文中将始终引用A::B::Test
,因此您需要明确地说,您需要全局命名空间中的Test
,这正是::Test
的作用< / p>