The classloader train on rails!
That's when everything works on your development workstation, in development and production mode, but it won't work on your production system.
That's when you check every line of your controllers code, every line of your models code.
But don't fear, there is an easy way to debug this and an easy way to prevent this in the future!
How to debug this:
Since ruby is a really really code language, try this:
Put a puts statement before and after your class!
puts 'start loading account_class'
class Account < ActiveRecord::Base
# your code here
end
Once you're finished, just try this:
script/console
You will see something like this:
devws:/development/projects/demo art$ script/consoleLoading development environment.
start loading account
end loading account
start loading xxx
end loading xxx
Now login to your production, errr, integration system, and try this again.
One thing that really shocked me, was:
On Mac OSX (my workstation) every model was loaded.
On Linux (my production system) one model was missing!
Okay, I just had 19 models, so it was easy to track down the missing class :)
But, you can go even further - put a puts statement before and after your methods:
puts 'start loading account_class'
class Account < ActiveRecord::Base
puts 'before doSomethingWithADifferentClass'
def doSomethingWithADifferentClass
end
puts 'after doSomethingWithADifferentClass'
end
That's how you can track down, if your methods get fully loaded.
How to prevent this in the future:
1) Put your requires where the belong (environments.rb could be loaded after your model class)
2) Put your require statements in the classes that need them
3) Be careful when you use memcached -> when you unmarshal an object (get it out of memcached) the class needs to be loaded first!
One additional info:
In development mode, all classes are reloaded everytime. In production mode classes are only loaded once :)
My models and even my controllers have now their require statements - I hope this help a bit!
As usual, once you know what hits you, you know how to search for more information and find these resources:
http://duncandavidson.com/archives/285
http://mojodna.net/2007/02/12/classloading-in-rails/