views:

62

answers:

2

Hey folks,

I have following models:

class App::Module::Object < AR::Base
  has_many :objects, :class_name => 'App::OtherModule::Object'
end

and

class App::OtherModule::Object < AR::Base
  belongs_to :object, :class_name => 'App::Module::Object'
end

Using Rails 3.0.0 and Ruby 1.9.2, I get following error after accessing App::Module::Object.first.objects:

NameError: uninitialized constant App::Module::Object::OtherModule::Object

For clearness: Rails generate the wrong class name, App::Module::Object::OtherModule::Object instead of App::OtherModule::Object. It appends the :class_name attribute to the current namespace, instead of replacing it.

Unfortunately same code is working in Rails 2.0, hope anyone out there can help me?

Greetz Mario

A: 

Rails 3 is not autoloading files from lib anymore. So you need add it if you want the same result in your application.rb

config.autoload_paths += %W( #{#{config.root}/lib )

or you could just require each of the files you want.

shingara
But my files are not located in lib. They are ordinary AR models, located in app/models.
ream88
what is the real name of this module and where exactly is this file ?
shingara
A: 

Seems to be a typo, fixed, but Rails behavior is strange. Whatever, thank you guys. :)

ream88