Sharing a Model


#1

I have two rails applications that modify/view the same data. Is there
a DRY way of sharing a model (not just database) between two separate
applications?


#2

You can use svn:externals if you’re using subversion.

One thing I’d like to know from people with more experience is how to
package up unit tests when using svn:externals. I have a couple
models that I store in a lib dir external to all my projects, but I’m
not sure how to handle unit tests.

Pat


#3

I would be pretty interesting if you did some drb experiments on this
topic…

could be the, dare i say, ejb of rails…

M

Mike Douglas wrote:

I have two rails applications that modify/view the same data. Is there
a DRY way of sharing a model (not just database) between two separate
applications?


#4

On 20/01/06, Pat M. removed_email_address@domain.invalid wrote:

You can use svn:externals if you’re using subversion.

One thing I’d like to know from people with more experience is how to
package up unit tests when using svn:externals. I have a couple
models that I store in a lib dir external to all my projects, but I’m
not sure how to handle unit tests.

Have you tried making an engine out of common models? I think I have
seen a
patch allowing to unit-test engines so this should be a perfect
solution.


#5

No, save us, no!


#6

Engines provide some support for testing out of the box, although it
could be improved, with suggestions.

  • james

#7

Mike Douglas wrote:

I have two rails applications that modify/view the same data. Is there
a DRY way of sharing a model (not just database) between two separate
applications?

Ran into this not long ago. We have one main database, and at present
are running three main apps off of it. Here is the setup on our server:

www

  • main_app
  • side_app
  • side_app_2

So, both side apps need to share the models from the main app. So what I
did was remove any models from the side_app that needed to be shared
from the main app. Then, in each side app’s environment.rb I added this:

if ENV[‘RAILS_ENV’] == ‘production’
config.load_paths += %W( /home/user/www/main_app/app/models )
else
config.load_paths += %W( /users/user/sites/main_app/app/models )
end

This needs to go in the Rails Initiator block in environment.rb (look
for the commented config.load_paths line)

The first part of the conditional makes sure the production box loads
the models from the main app, the second part makes sure it works on my
development machine.

A few caveats: You are only sharing the models, so tests aren’t along
for the ride. I am assuming you can do the same thing and add the tests
folder to the load path as well. Also, any changes to the main app’s
models requires a restart of all dependent apps, obviously.