environment variables unknown in Model with Namespace


I have a problem with a model which is defined within a namespace. It
does not seem to find another namespace that was defined in the

module X
  class Exception < Exception
    ...some custom exception definitions here...

class Y::MyModel < ActiveRecord::Base
  validates_presence_of :attr, :message =>

This setup fails during boot because the model searches for
Y::MyModel::X, which it cannot find:
dependencies.rb:478:in `const_missing':NameError: uninitialized
constant Y::MyModel::X"

When I try the following setup:

class Y::MyModel < ActiveRecord::Base
  validates_presence_of :attr, :message
=> ::x::Exception.new('init).to_string_reference

It still fails during boot because it still cannot find X:
dependencies.rb:266:in `load_missing_constant':NameError:
uninitialized constant X"

However, in my normal models (without a namespace) it does work:

class MyOtherModel < ActiveRecord::Base
  validates_presence_of :attr, :message =>

This loads fine. I don't understand why it does not work in the
namespace situation. Does anybody know what I'm doing wrong? I'm using
Rails 2.0RC1 by the way.

Thanks in advance,
Bas van Westing

To give a brief explanation constant autoloading assumes two things about a missing constant with qualified name "Foo::Bar":

   1. The definition lives in a file whose filename ends
      with "Foo::Bar".underscore + '.rb'

   2. The resulting path "foo/bar.rb" exists under one of the
      directories in Dependencies.load_path

When Rails boots Dependencies.load_path is initialized with an array of standard directories (like RAILS_ROOT/app/models and friends), but since "X" is defined in config/initializers.rb it won't be autoloaded (that file is non-standard AFAIK, are you sure that's its name?).

-- fxn

Hi Xavier,

The config/initializer.rb was a typo. It is in config/initializers/
The config/initializers/* files are loaded on boot by default with
rails 2.0RC1.

The problem is still unclear to me because the constant is available
in the other model (without the module/namespace). Both models are
loaded in the same boot, so that cannot be the problem. Do you have
any more ideas?

Thanks, Bas