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:
/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.
O yeah run
is a class method i.e. def self.run .... end
Any suggestions?
The Uninitialized Constant error is a variation of a regular NameError exception class. It has several possible causes. You'll see this error when the code refers to a class or module that it can't find, often because the code doesn't include require, which instructs the Ruby file to load the class.
NameError is raised when you reference a constant or a variable which isn't defined in the current context. A ruby constant can be a Module, Class, or a CONSTANT_VARIABLE, and must always start with an upper case letter.
That error occurs when ruby can't find a Class or Module. I'd start out by:
Hope that helps.
update Just to summarise the comments it was option 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:
I had multiple class definition(all STI classes) on the same file. and when I separated the definition into their respective files, It works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With