Forum: Ruby on Rails Sharing a Model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c9df8192dfebf429c5a8b8d9ba0f630?d=identicon&s=25 Mike Douglas (Guest)
on 2006-01-20 10:53
(Received via mailing list)
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?
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-20 12:08
(Received via mailing list)
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
C7669e8b5676f61fdf202230cbcf72d8?d=identicon&s=25 mikkel (Guest)
on 2006-01-20 12:13
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?
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-01-20 18:03
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.
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-01-20 18:59
(Received via mailing list)
On 20/01/06, Pat Maddox <pergesu@gmail.com> 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.
36bb02bc0b50dc9a10b0c6ce2b13590e?d=identicon&s=25 Skott Klebe (Guest)
on 2006-01-20 19:09
(Received via mailing list)
No, save us, no!
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-20 19:24
(Received via mailing list)
Engines provide some support for testing out of the box, although it
could be improved, with suggestions.

- james
This topic is locked and can not be replied to.