# Enhancing model in one engine from another

**URL:** <https://www.ruby-forum.com/t/enhancing-model-in-one-engine-from-another/55346>\
**Category:** Engines Development\
**Created:** [March 20, 2006, 4:15am UTC](https://www.ruby-forum.com/t/enhancing-model-in-one-engine-from-another/55346 "2006-03-20T04:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vor\_lord](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ec8ea/32.png) [@vor\_lord](https://www.ruby-forum.com/u/vor_lord)\
**Post date:** [March 20, 2006, 4:15am UTC](https://www.ruby-forum.com/t/enhancing-model-in-one-engine-from-another/55346/1 "2006-03-20T04:15:13Z")

</div>

Hi,

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.

(…time…)

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?

Thanks,  
Brett

---

<div class="post-metadata">

**Author:** ![vor\_lord](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ec8ea/32.png) [@vor\_lord](https://www.ruby-forum.com/u/vor_lord)\
**Post date:** [March 21, 2006, 1:57am UTC](https://www.ruby-forum.com/t/enhancing-model-in-one-engine-from-another/55346/2 "2006-03-21T01:57:23Z")

</div>

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

vendor/plugins/engine1/app/models/model1.rb:  
class Model1 \< ActiveRecord::Base; end

and

vendor/plugins/engine2/app/models/model2.rb:  
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  
this).

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](mailto: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  
> [http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-developers-rails-engines.org)

–

- J \*  
~
