2

I've got an existing webapp running on Rails. The plan is to setup a new server which will provide an API service, and eventually update the webapp to be a client of this API.

It seems like a good approach to achieving this would be packaging all the models as gems and sharing them between the two applications. Eventually the API service would be monolithic - containing all the models, but there is a period of development/migration where models will need to be shared.
Both the API and the webapp will be using the same database.

  • What do I need to consider before jumping into packaging up all my models?
  • Would it be worthwhile to package all the models into a single gem, individually package each model, or do some sort of logical grouping of models?
  • How would I approach dependencies for gems?

For reference, here's a similar-ish question: Sharing models between Rails apps using gems

I'm also just getting familiar with packaging Ruby code as a Rubygem. (This might explain some of my questions above.)

[edit] I'm using Rails 2.3.14, not Rails 3.X.

Community
  • 1
  • 1
GrooveStomp
  • 374
  • 3
  • 18
  • 2
    If the app on the new server provided a real API, you wouldn't have to even share models between all the apps using this api, right? But if you want to share the models, it seems like this would be very easy if you were using rails 3.1. You could just create an engine with all the models and the related libs for instance. – Robin Dec 06 '11 at 21:11
  • Right, the eventual goal will be that the models are contained within the API engine, as I mentioned. :) – GrooveStomp Dec 06 '11 at 21:27

1 Answers1

1

We have done packaging models to a gem in the past. We started out by moving a group of models that are associated with each other but have no other dependency of the rest of the models. Then we slowly move another group. It is a bit painful but we eventually did it. The model gems are shared among several apps.

DrChanimal
  • 681
  • 5
  • 10
  • Thanks DrChanimal. I'm in the process of experimenting with this right now. How do you manage dependencies? Our environment.rb specifies most of our dependencies, but obviously these don't exist within the separated model gem. – GrooveStomp Dec 06 '11 at 23:39
  • You can specify the depending gems on Gemfile if you are using rails 3 or above and then use bundler to manage the installing the gems assuming that you put your gems in some gem server. – DrChanimal Dec 08 '11 at 00:00