# How to share a collection of model files across many apps?

**URL:** <https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393>\
**Category:** ruby-talk\
**Created:** [23 March 2007 15:24 UTC](https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393 "2007-03-23T15:24:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elliott\_Blatt](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Elliott\_Blatt](https://rubytalk.org/u/Elliott_Blatt)\
**Post date:** [23 March 2007 15:24 UTC](https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393/1 "2007-03-23T15:24:27Z")

</div>

Hi,

I've got three files that (a.rb, b.rb, c.rb) that currently live in  
app/models.  
I'd like these models to shared by multiple rails apps. These models are  
associated with a separate database.

My rails projects are contained in a directory that looks like this:

projects/

proj1/ proj2/ proj3/ common/

common/  
a.rb b.rb c.rb

My idea is to do this:

In proj1/lib/, symlink to ../../common/

lib/  
&nbsp;&nbsp;common/ (which is a symlink)

My question is:  
How do I tell rails to load the files pointed to by the symlink named  
'common' in the lib directory?

I've tried:

cofig/environment.rb

include 'lib/common'

Thanks for your input.  
EB

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Phil](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@Phil](https://rubytalk.org/u/Phil)\
**Post date:** [23 March 2007 16:58 UTC](https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393/2 "2007-03-23T16:58:01Z")

</div>

Elliott Blatt wrote:

> Hi,
> 
> I've got three files that (a.rb, b.rb, c.rb) that currently live in  
> app/models.  
> I'd like these models to shared by multiple rails apps. These models are  
> associated with a separate database.
> 
> My rails projects are contained in a directory that looks like this:
> 
> projects/
> 
> proj1/ proj2/ proj3/ common/
> 
> common/  
> a.rb b.rb c.rb
> 
> My idea is to do this:
> 
> In proj1/lib/, symlink to ../../common/
> 
> lib/  
> &nbsp;&nbsp;common/ (which is a symlink)
> 
> My question is:  
> How do I tell rails to load the files pointed to by the symlink named  
> 'common' in the lib directory?

First, you might want to ask this at the Rails Mailinglist.

Secondly, your solution wouldn't be portable, as only Unixes (MacOS, HP-UX, OpenSolaris, Linux) understand symlinks. Windows doesn't understand POSIX symlinks at all.

> **···**
>
> --  
> Phillip "CynicalRyan" Gawlowski
> 
> Rule of Open-Source Programming #15:
> 
> If you like it, let the author know. If you hate it, let the author  
> know why.

---

<div class="post-metadata">

**Author:** ![RubyTalk](https://avatars.discourse-cdn.com/v4/letter/r/9fc29f/32.png) [@RubyTalk](https://rubytalk.org/u/RubyTalk)\
**Post date:** [23 March 2007 17:44 UTC](https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393/3 "2007-03-23T17:44:10Z")

</div>

If you are using svn:

svn externals works well for this. I would create a tag of the libs so  
when you create tags of your projects you will not have to change the  
external -r option.

[http://svnbook.red-bean.com/en/1.0/ch07s03.html](http://svnbook.red-bean.com/en/1.0/ch07s03.html)

There are unix programs that will keep directories synced.

Stephen Becker IV

> **···**
>
> On 3/23/07, Elliott Blatt \<elliott\_blatt@yahoo.com\> wrote:
> 
> > Hi,
> > 
> > I've got three files that (a.rb, b.rb, c.rb) that currently live in  
> > app/models.  
> > I'd like these models to shared by multiple rails apps. These models are  
> > associated with a separate database.
> > 
> > My rails projects are contained in a directory that looks like this:
> > 
> > projects/
> > 
> > proj1/ proj2/ proj3/ common/
> > 
> > common/  
> > a.rb b.rb c.rb
> > 
> > My idea is to do this:
> > 
> > In proj1/lib/, symlink to ../../common/
> > 
> > lib/  
> > &nbsp;&nbsp;common/ (which is a symlink)
> > 
> > My question is:  
> > How do I tell rails to load the files pointed to by the symlink named  
> > 'common' in the lib directory?
> > 
> > I've tried:
> > 
> > cofig/environment.rb
> > 
> > include 'lib/common'
> > 
> > Thanks for your input.  
> > EB
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [23 March 2007 20:44 UTC](https://rubytalk.org/t/how-to-share-a-collection-of-model-files-across-many-apps/36393/4 "2007-03-23T20:44:07Z")

</div>

I'm going to have to do something like this soon.

Personally I want to avoid symlinks, and I think what you want should be  
possible simply by adding the appropriate directory to config.load\_paths,  
e.g.

&nbsp;&nbsp;&nbsp;&nbsp;config.load\_paths \<\< "#{RAILS\_ROOT}/../common/app/models"

Now, if you enter "site:rubyonrails.com config.load\_paths" into Google,  
there are two hits, and the second one looks like a Wiki page which explains  
exactly this. Unfortunately, when I follow it at the moment all I see is  
"Application error (Rails)" ☹

But the 'Cached' link on Google works.

Another idea. If the model is called common/app/models/foo.rb, then you can  
create stub files {proj1,proj2,proj3}/app/models/foo.rb which just contain  
a single line:

&nbsp;&nbsp;require "#{RAILS\_ROOT}/../common/app/models/foo.rb"

or even something which does a sub() on \_\_FILE\_\_

Regards,

Brian.

> **···**
>
> On Sat, Mar 24, 2007 at 12:24:27AM +0900, Elliott Blatt wrote:
> 
> > I've got three files that (a.rb, b.rb, c.rb) that currently live in  
> > app/models.  
> > I'd like these models to shared by multiple rails apps. These models are  
> > associated with a separate database.
> > 
> > My rails projects are contained in a directory that looks like this:
> > 
> > projects/
> > 
> > proj1/ proj2/ proj3/ common/
> > 
> > common/  
> > a.rb b.rb c.rb
> > 
> > My idea is to do this:
> > 
> > In proj1/lib/, symlink to ../../common/
> > 
> > lib/  
> > &nbsp;&nbsp;common/ (which is a symlink)
> > 
> > My question is:  
> > How do I tell rails to load the files pointed to by the symlink named  
> > 'common' in the lib directory?
