停止 Rails Console 加载 Test::Unit
我有一个名为“Test”的模型(我注释了该模型中的所有内容,因此剩下的就是用于调试目的的 class Test
end
),每次我尝试实例化它时Rails 控制台出现错误,指出 Test:Module
不存在“新”方法。实例化我的任何其他模型时不会发生此错误,我认为这与 Rails 控制台正在加载 Test::Unit 或类似的东西有关(凭直觉我运行了 Test.constants
并且控制台返回了 [:Unit]
,所以我很确定这就是问题所在)。无论如何,毫无疑问,rails 控制台正在运行一些名为 Test 的模块,我不希望这种情况发生。我该如何避免这种情况?将类名更改为不同的值对我来说非常不方便,所以如果有任何方法可以解决这个问题那就太好了~!
I have a model named "Test" (I commented everything out of that model so all that's left is class Test
end
for debugging purposes) and every time I try instantiating it in the rails console I get an error that the "new" method does not exist for Test:Module
. This error does not occur when instantiating any of my other models, and I think it has to do with the fact that the rails console is loading up Test::Unit or something like that (on a hunch I ran Test.constants
and the console returned [:Unit]
, so I am pretty sure that's the issue). At any rate, there is no question that some module named Test is being run by the rails console, and I don't want this to happen. How do I avoid this? It would be highly inconvenient for me to change me class name to a different value, so if there is any way to resolve this issue that would be great~!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加一个模块并将测试类放入其中以避免该问题。然后,您需要像 module::class 一样对您的类进行寻址。
You could add a module and have your test class inside of it to avoid that issue. You will then need to address your class like module::class.
我只是使用了一个简单的解决方法,将我的类称为“考试”而不是“测试”,但我想知道如何在不解决问题的情况下正确解决此问题。
I just used a simple work-around of calling my class "Exam" instead of Test, but I would like to know how to resolve this correctly without working around the issue.