# Putting models into Gems (not plugins)

**URL:** <https://www.ruby-forum.com/t/putting-models-into-gems-not-plugins/171061>\
**Category:** Rails\
**Created:** [June 25, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/putting-models-into-gems-not-plugins/171061 "2009-06-25T22:45:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 25, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/putting-models-into-gems-not-plugins/171061/1 "2009-06-25T22:45:39Z")

</div>

Hi, we internally are creating gems out of particular sets of models,  
both to share them among multiple Rails apps, but also to use them  
within background scripts.

If possible, I’d like for the models to function with ActiveRecord/  
ActiveSupport as the only dependencies and not require a full Rails  
environment. This is for the purposes of our background jobs which  
use the same set of models. This way it becomes much easier to create  
and modularize the background processes as they aren’t dependent on  
the full Rails environment.

I’ve run into a number of different problems trying to homebrew this  
sort of thing. The latest comes from me trying to give each set of  
models its own migrations table so that I can use many of them with  
the same database.

Has someone put together a good solution for this? I’ve been hobbling  
along with my own monkeypatches to things like ActiveRecord::Migrator  
and so far this has proven a rather cumbersome solution.

The latest problem I’ve encountered was on our CI server only: I’m  
getting a “No database selected” error after the test database is  
purged and it’s calling “SHOW TABLES”. For some reason everything  
works just dandy locally.

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [June 26, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/putting-models-into-gems-not-plugins/171061/2 "2009-06-26T16:08:30Z")

</div>

On Jun 25, 1:58 pm, Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve run into a number of different problems trying to homebrew this  
> sort of thing. The latest comes from me trying to give each set of  
> models its own migrations table so that I can use many of them with  
> the same database.

There’s still some discussion on the best way to do that - see this  
ticket:

[https://rails.lighthouseapp.com/projects/8994/tickets/2058-rake-tasks-for-run-engine-migrations](https://rails.lighthouseapp.com/projects/8994/tickets/2058-rake-tasks-for-run-engine-migrations)

–Matt J.
