Forum: Rails Engines Engines' related Rails Development Mode errors (solved I think)

Posted by Pascal Rettig (Guest)
on 2008-01-05 19:46
(Received via mailing list)
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
Posted by Sean Schofield (Guest)
on 2008-01-05 19:53
(Received via mailing list)
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
Posted by James Adam (Guest)
on 2008-01-05 20:52
(Received via mailing list)
My comments on this ticket might also be relevant -
http://dev.rubyonrails.org/ticket/10488#comment:6
Posted by Pascal Rettig (Guest)
on 2008-01-05 23:46
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.