Inheritance breaks in dev mode - Dependency reloading bug?

I have a plugin that creates an abstract ActiveRecord class that other
models are to inherit from.

module MyPlugin
class MyClass < ActiveRecord::Base
self.abstract_class = true
# methods
end
end

Then the use of the plugin simply has to do the following to use it’s
functionality:

class Foo < MyPlugin::MyClass
end

The problem is in the development environment. Apparently some systems
are getting a “uninitialized constant MyClass” error after the first
request, but works fine on other systems.

It’s like Rails is wiping out the definition for MyPlugin::MyClass but
never reloads it.

My init.rb simply requires the file and doesn’t do anything tricky with
it that might only be executed at load time.

It DOES WORK however if I rename the class so it’s not in the namespaced
module. Meaning instead of MyPlugin::MyClass, MyPluginMyClass. This
seems to solve the issue, but I really don’t like from a purely semantic
point of view. I really want all the code for this plugin to be inside
this single name spaced module.

Is this a bug in dependency reloading?

On Aug 22, 2006, at 10:00 AM, Alex W. wrote:

I have a plugin that creates an abstract ActiveRecord class that other
models are to inherit from.

Try putting your file into vendor/plugins/your_plugin/lib/my_plugin/
my_class.rb instead of your_plugin/lib/my_class.rb when its
MyPlugin::MyClass. When there’s a module involved, Rails’
autoloading assumes a directory.


Chris W.
http://errtheblog.com

Ah thank you that was indeed the problem. And it was working on edge,
and not 1.1.6 because the new Dependency code does not have this
limitation.

Thanks for the help!