Forum: Ruby on Rails uninitialized constant oddities

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jens wille (Guest)
on 2007-01-06 20:30
(Received via mailing list)
hi there!

unfortunately, we are repeatedly having problems with uninitialized
constants in our rails app (v1.1.6), which is running on a mongrel
cluster behind apache's mod_proxy_balancer.

---- snip ----
NameError (uninitialized constant Base):
    /app/models/image.rb:90:in `subclasses'
    /app/models/image.rb:98:in `subclass?'
    /app/models/image.rb:261:in `count'
    /app/controllers/image_controller.rb:95:in `list'
---- snip ----

"Base" is actually "Image::Base", defined in lib/image/base.rb:
class Image::Base.

immediately after a mongrel_cluster restart it's working for a few
requests, though. (approx. 4 requests, resulting from 4 mongrel
servers being run?) the strange thing just is that everything works
fine when run from script/console ... except when commenting out the
"require 'image/base'" from config/environment.rb! -- how come?

code details are as follows:

app/controllers/image_controller.rb: class ImageController <

---- snip ----
  def list
    # Image.count is where all evil originates
    @images =, 10) { |offset, per_page|
      Image.find(:all, :limit => per_page, :offset => offset)
---- snip ----

app/models/image.rb: class Image < Entity (Entity < ActiveRecord::Base):

---- snip ----
  def count
    return super if subclass?

    subclasses.inject(0) { |sum, klass|
      sum += klass.count

  def subclass?
    subclasses.include? self

  # here's where the uninitialized constant comes in
  def subclasses(table_must_exist = true)
    Image::Base.subclasses table_must_exist
---- snip ----

any ideas on what might cause this (mis-)behaviour would be greatly

TIA & cheers

Jens W., Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
An St. Laurentius 4, 50931
KölnTel.: +49 (0)221 470-6668, E-Mail: removed_email_address@domain.invalid
This topic is locked and can not be replied to.