Forum: Rails Engines development Enhancing model in one engine from another...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Brett W. (Guest)
on 2006-03-20 05:15
(Received via mailing list)

I need some help.  I've got two engines.  From within the second
engine, I need to extend a model in the first engine.

I've tried putting the code everywhere.  It kind of works when it's
in the lib directory.  But only the first time after the engine
starts.  Then it can't it can't find the extra functions anymore.
Where is the right place to do this in an engine?

For the interested, I'm extending the User model in active_rbac to
hook into a more extensive permission system.


Ok, now I remember that it says in the read me you can't really do
this, yet.  Does this have something to do with the engine loading
system?  Is there hope for the future?

James A. (Guest)
on 2006-03-21 02:57
(Received via mailing list)
Hi Brett,

With models (and other library code), the Engines plugin will only
load the first file for a given name that it finds. So, if you have an
engine with a 'Blah' model, and a second engine which has a newer
'Blah' model that you want to inherit from the first engine, you're
going to need to use namespaces to distinguish between those models.

However, if you have

    class Model1 < ActiveRecord::Base; end


    class Model2 < Model1

... then that *should* work (you'll need to set up your DB table to
deal with STI though).

If you're trying to add methods to an existing model, rather than
subclass it, that's where the current wrinkles are with the engine
model loading process. I've recommended that engine developers provide
their model classes as 'stubs' with most of the functionality in
models for this reason (see the login/user engines for examples of

The above said, I'm not 100% familiar with how ActiveRBAC is built, so
you might want to get in touch with those guys directly.

- james

On 3/20/06, Brett W. <removed_email_address@domain.invalid> wrote:
> For the interested, I'm extending the User model in active_rbac to
> _______________________________________________
> engine-developers mailing list
> removed_email_address@domain.invalid

* J *
This topic is locked and can not be replied to.