Re: Overriding code from one engine with another (extending

Suppose I want to make an engine that builds on another
engine. Extending engine code is pretty trivial in the application -
but what about in another engine?

I’m by no means an expert on engines, but I’ve been trying to do
something similar and thought I’d share my experience.

Specifically, I customized the UserEngine and LoginEngine in an
application for my company, then realized I wanted the same
customizations in more than one app.

So I’ve been trying to make an Engine out of those customizations. And
I think I’ve pretty much got it working. But not without some trouble.

  1. Your application (not the plugin you’re creating) must not only load
    the plugins in the correct order in environment.rb, but must include the
    relevant modules in the right order in, say, ApplicationController (and
    ApplicationHelper if applicable). This is probably obvious to someone
    with more Engines experience, but it tripped me up for a while b/c I got
    weird errors, for example, my Permission class was defined but without
    any of the code from in UserEngine’s permission.rb.

  2. Plugins might be loaded (or require’d) in other places. These have
    to be in order also. I ran into trouble trying to bootstrap the
    UserEngine because Permission.synchronize_with_controllers manually
    requires each controller class – it makes sure to require engines’
    controllers before the app’s controllers, but doesn’t specify an order
    (other than filesystem order) to look at the various engines. (I hacked
    it so it would require LoginEngine’s controllers first, then
    UserEngine’s, then other engines).

-Brian