Hi All, I'm pretty new to Engines, but in upgrading a Rails application to 2.0 I decided to move a bunch of modules from the deprecated "components" directory to a new "vendor/modules" directory and Engines seemed like the best drop-in replacement to do so. Everything was great in production mode, but in development mode I kept getting a bunch of strange errors of two different sorts: - Method missing errors from Models that were defined in the code - "A copy of XXX has been removed from the module tree but is still active!" errors for Application Controllers This is probably old hat to people who have been using engines for a while, but I need to add the following to my init.rb to solve the issues: load_paths.each do |path| Dependencies.load_once_paths.delete(path) end The reason for my issues is that I'm using the engine plugins in a way that they refer back to models and controllers in the main application, so they need to be reloaded in a similar method to the main application controllers & models or the class constant references will become stale on page refreshes. Took me a couple hours of head banging on keyboard to figure this out so maybe this info will help someone else. -Pascal
on 05.01.2008 19:46
on 05.01.2008 19:53
Hey did you just read my email before posting that? If not, that was a scary coincidence. Question about your solution ... Which init.rb do you paste that code? In the engines plugin or the plugin that is relying on engines? Sean
on 05.01.2008 20:52
My comments on this ticket might also be relevant - http://dev.rubyonrails.org/ticket/10488#comment:6
on 05.01.2008 23:46
Hi,
That is remarkable cross post, I didn't see Sean's message until just
now.
>From the ticket James posted, I think the comment that plugins only need
to be reloaded during development is probably 99% true, except in
situations where the plugin refers to application classes by constant
(as opposed to something like ClassName.constantize) - which happens to
be my situation - in which case they will need to be reloadable in
development mode even after the plugin is no longer in development,
either via require_dependency in the source app or removing it from the
load_once list.
For engines, require_dependency isn't really a solution I don't think as
pre-loading controllers would be a pain, especially with a bunch of
routes. Maybe just adding a function to Engines that has the same effect
as the code I posted would be enough.
The code I posted goes in the init.rb of the each plugin that needs to
be marked as reloadable (not the engines plugin itself)
-Pascal