我有一个命名空间路由,下面是我创建 Controller 的方式:
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 的常量 Test (A::B::Test
) ?
我得到的错误是:
NameError (uninitialized constant A::B::Test::Dummy)
最佳答案
试试 ::Test::Dummy::Something
Test
在此上下文中将始终引用 A::B::Test
因此您需要明确说明您需要 Test
来自全局命名空间,这正是 ::Test
所做的
关于ruby-on-rails - rails : Uninitialized Constant inside Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53168654/