[英]`const_missing': uninitialized constant (NameError)
Every time I try to run any class from my rails 2.2 app's lib directory using "script/runner -e production ClassName.run" I get the following error:每次我尝试使用“script/runner -e production ClassName.run”从我的 rails 2.2 应用程序的 lib 目录中运行任何 class 时,都会出现以下错误:
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/runner.rb:47:
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing': uninitialized constant ClassName (NameError)"
For some reason I don't get this error when I run it as test
instead of production
, and everything works fine.出于某种原因,当我将其作为
test
而不是production
运行时,我没有收到此错误,并且一切正常。
O yeah run
is a class method ie def self.run.... end
哦,是的
run
是一种 class 方法,即def self.run.... end
Any suggestions?有什么建议么?
That error occurs when ruby can't find a Class or Module.当 ruby 找不到 Class 或模块时,会发生该错误。 I'd start out by:
我会开始:
Hope that helps.希望有帮助。
update Just to summarise the comments it was option 4.更新只是为了总结意见,它是选项 4。
Unless you only want to load the lib in production you should think about making sure all environments load the lib by doing one of the following:除非您只想在生产中加载 lib,否则您应该考虑通过执行以下操作之一来确保所有环境都加载 lib:
I had multiple class definition(all STI classes) on the same file.我在同一个文件中有多个 class 定义(所有 STI 类)。 and when I separated the definition into their respective files, It works
当我将定义分成各自的文件时,它可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.