From: Brian Candler Date: 2007-03-24T05:44:07+09:00 Subject: Re: How to share a collection of model files across many apps? 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/ > 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'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. 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: require "#{RAILS_ROOT}/../common/app/models/foo.rb" or even something which does a sub() on __FILE__ Regards, Brian.