"Object is not missing constant" in rails / rake 05. April 2010 um 17:09 Uhr / Programming
I just spend several hours on a bug in rails where I just got this error:
Object is not missing constant Image!
The problem was in a rake task file which looked like this:
image = page.images.find_or_initialize_by_code(img[:code])
It did work fine in development environment, but not in production where I have this line: config.cache_classes = true which caused the problem. It seems that rails' "smart" and lazy class loader was confused and didn't load the Image model but just outputted the error.
I could convince it to load it by adding just this to the beginning of the rake task:
desc "Update the pages" task :pages => :environment do Image.new # Bugfix for the class autoloader # ... image = page.images.find_or_initialize_by_code(img[:code]) # ... end
And now everything seems to work as it should.




abonnieren.
Daniel aus Leipzig schrieb am 11.06.2011
Danke für den Tip hatte das gleiche Problem grad und bin auf der Suche nach "Object is not missing constant" auf den Eintrag gekommen. Die Lösung hat funktioniert und läuft jetzt wieder wie gewünscht.