Reputation: 1101
I have the following code:
class MyClass
def method
foo = MyClass.all
end
end
which results in this error:
NameError (uninitialized constant MyClass::MyClass)
It works fine if I change it to self.all, but the existing code works fine when I deploy to Heroku. It's only broken on my local system.
This is with a Rails 3.1.1 app and Ruby 1.9.2
Any ideas what's up?
Upvotes: 0
Views: 70
Reputation: 7480
You shouldn't have to do that. Assuming all
is a class method and is not an instance method, do
class MyClass
def method
foo = self.class.all
end
end
However, I think what's causing your problem is that in production, classes are cached. In development, they get reloaded on every request.
Upvotes: 1