Daniel Berlinger asks a good question about my Sharing models between two Rails applications using Piston asking:

Without having a moment to think about it… there must be other ways to accomplish this (in Rails) without Piston, and other Subversion trickery. No?

Daniel Berlinger

I know of only one way to do it: create a plugin to hold the models, and load this plugin into all of the applications that need the shared models.

I recently had to share specifications and models between two applications. Here’s how I did it:

  1. Create a shared/ directory in Subversion
  2. svn copy the current models there
  3. svn copy the specifications (or unit tests)
  4. svn remove the app/models and spec/ folder from your project root
  5. piston import /shared/app/models app/models
  6. piston import /shared/spec spec/

The nice thing about this technique is that you can add models to one or the other application and they won’t care about it. You have to be careful not to have name clashes though.

Example

You have one application in your repository named flow/. You are creating a new one named /bark. Here are the steps ($REPOS_ROOT is obviously your repository root):


1 $ svn mkdir $REPOS_ROOT/shared $REPOS_ROOT/shared/app -m "Creating shared models root"
2 $ svn move $REPOS_ROOT/flow/trunk/app/models $REPOS_ROOT/shared/app/models
3 $ svn move $REPOS_ROOT/flow/trunk/spec $REPOS_ROOT/shared/spec # or test/
4 $ svn checkout $REPOS_ROOT/flow/trunk
5 $ cd trunk
6 $ piston import $REPOS_ROOT/shared/app/models app/models
7 $ piston import $REPOS_ROOT/shared/spec spec
8 $ svn commit -m "Copied shared models back in using Piston"

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on