Another Engines 2.0 problem

I’m having a brand new problem that seems to be caused by either
Engines 2.0 and/or Rails 2.0.2. Everything was working fine until I
upgraded both of these. I’m getting this message when I refresh a
page.

A copy of Tag has been removed from the module tree but is still active!

This looks like a similar problem to a previous post[1] on this forum.
In particular this line from that post seems relevant:

“Engines now rely on Rails’ own plugin
mechanisms. I seem to remember that I’ve seen an error like this when
references to a class are saved somewhere and the class then gets
reloaded in development mode while the reference holding object
doesn’t.”

I guess I could use some more information on how things were changed.
I don’t know much about the loading mechanism of Rails yet so I’m at a
loss as to how to fix it. The Tag stuff comes from
has_many_polymorphs. Tag is a model defined in the main application
and Product is a model defined in the plugin. I suspect this might be
the problem but I have no idea how to go about fixing it.

TIA,

Sean

[1] Engines 2.0/trunk with Rails 2.0 - Engines Development - Ruby-Forum

This problem normally indicates that Rails’ dependencies are trying to
reload a class, but a reference to the class is maintained by another
object which isn’t reloaded. In this case, it could be that your
Product model refers to Tag, and we hit the error when Tag reloads.

You might try making your Product model reloadable (require it via
require_dependency, rather than relying on Rails’ autoloading)?

I had this problem too, I think it’s because rails doesn’t reload plugin
classes by default now. Somehow that ends up causing the crash here.
Definitely one of the more annoying crashes because it’s nothing obvious
with your code.

I talked to one of the rails guys a bit in this ticket,
http://dev.rubyonrails.org/ticket/10488

And his suggestion here worked:

  • Add an after_initialize hook in your development environment:

config.after_initialize {
Dependencies.load_once_paths = []
}

-Andrew

Am 05.01.2008 um 21:43 schrieb Andrew R.:

config.after_initialize {
Dependencies.load_once_paths = []
}

Amazing. That’s a nice tip.

Thanks!


sven fuchs [email protected]
artweb design http://www.artweb-design.de
grünberger 65 + 49 (0) 30 - 47 98 69 96 (phone)
d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile)