"Object is not missing constant" in rails / rake 05. April 2010 um 17:09 Uhr / Programming

Eingestellt am 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])
	# ...

And now everything seems to work as it should.


Die Kommentare sind für diesen Eintrag geschlossen.