# How to share tables between Ruby Apps

**URL:** <https://www.ruby-forum.com/t/how-to-share-tables-between-ruby-apps/158795>\
**Category:** Rails\
**Created:** [January 28, 2009, 1:27am UTC](https://www.ruby-forum.com/t/how-to-share-tables-between-ruby-apps/158795 "2009-01-28T01:27:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [January 28, 2009, 1:27am UTC](https://www.ruby-forum.com/t/how-to-share-tables-between-ruby-apps/158795/1 "2009-01-28T01:27:02Z")

</div>

Hi,

We are in the process of rewriting our intranet applications in Ruby.  
We have one complete that requires an email invite being sent. We want  
to write another app that simply looks for unsent emails and sends  
them. This will be used by several ruby apps. How can we share this  
table(email details) across several Ruby apps?

Thanks,  
GARY LACKERMAN  
Software Developer

---

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [January 28, 2009, 3:12am UTC](https://www.ruby-forum.com/t/how-to-share-tables-between-ruby-apps/158795/2 "2009-01-28T03:12:23Z")

</div>

> How can we share this  
> table(email details) across several Ruby apps?

Sharing a table is straight forward. If they are in the same database,  
you simply call the class methods for this utility functionality. If  
the table exists in another database, you add that database to the  
database.yml file.

More importantly however, you want to avoid code duplication. You do  
not want to duplicate the code that looks for unsent emails in all  
your apps. You have several options. The first ones that come to mind  
are:

1. Write a utility rails app that does the looking for unsent emails  
and sending. All your other apps simply write to the table that stores  
these unsent emails. With this approach you can build views that allow  
you to see the queue, etc of all the emails, regardless of the app.

2. If you prefer to have the methods available in each app, then you  
want to look at the plugins facility in rails. You can write a plugin  
that gets used by all your apps. Then each of your apps gets the  
plugin from the same repository.

---

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [January 28, 2009, 4:50am UTC](https://www.ruby-forum.com/t/how-to-share-tables-between-ruby-apps/158795/3 "2009-01-28T04:50:44Z")

</div>

LaughingNinja wrote:

> Software Developer

You could create a message queue in a shared database of some sort. All  
applications insert their “to send” emails into the message queue  
(database table) and a regular job starts up and reads in the details  
and tries to send them. If it manages to send it, it cleans up for this  
record (i.e, deletes the item from the table and/ or informs someone).  
If it doesn’t manage to send the email, it increments some sort of  
“retry count” in the database and waits again. If a message fails to go  
after a certain number of tries, it simply marks the message as  
undeliverable and removes it from the message queue to a “failed items”  
database.

Now, I wonder if there is a message queue implementation in Ruby that  
does this?

Cheers,  
Mohit.  
1/28/2009 | 11:50 AM.
