views:

452

answers:

4

I have worked a bit with Django and I quite like its project/applications model : you can build a Django project by assembling one or more Django applications. These applications can be autonomous, or some applications can be built on top of other applications. An application can easily rely on another application's models, as well as its controllers (Django dudes call them "views") and even its views ("templates" in Django-speak).

I am now working on a relatively large scale Ruby on Rails project, and I am surprised to see that there is apparently no easy way to do the same thing in Rails. Basically, in Rails, one project = one application. Our project has started off as a huge monolithic app, and we are now trying to figure out how to split it into smaller chunks.

For example, our current application allows us to manage partners and contracts (among other things). I would like to have a "Partners" application which would manage our partners (address, contacts, etc.) and a "Contracts" application which would manage our contracts with our partners. The "Contracts" application would rely on the "Partners" application (but to avoid a circular dependency, I would like the "Partners" app to have no knowledge of the "Contracts" app).

For now, I see the following as the main options:

  1. make these applications communicate through REST requests (each app would act as a Webservice): this is nice, but it seems to prohibit reusing other applications' views. For example, if the "Partners" app has a nice page to show the details of a partner, and if I want to display that page, slightly modified, in the middle of the contract-details page, I see no other way to do this than to have the "Contracts" app ask the "Partners" app for the partner details through a REST request (it will get an object representation, not a view), then copy/paste the partner-details page's source code from the "Partners" app to the "Contracts" app.
  2. turn these applications into plugins : not as nice, and a bit more difficult, but seems to allow model & views reuse
  3. use svn external to share some models from application to application: simple but ugly.

Thanks for your advices.

A: 

The way I see it for RoR would be to write your "applications" as controllers in Rails. They can be quite independent but can share helpers and views. I do not know Django so maybe the terminology is different.

Keltia
+5  A: 

Since this is something I would also like to be able to do, I can offer four - incomplete and relatively untested (by me) "solutions":

In no particular order...

  1. Use the Rails engines plugin, which apparently works with 2.2 now. This, to some or all extent, will likely rolled into Rails 2.3 (see below)

  2. Switch to Merb, which has something called "slices" that might offer what you're looking for. Anyway, if this is correct (and who am I to doubt Yehuda Katz?) it'll all be the same thing one day anyway, which is cool.

  3. Take a look at the engines functionality in Edge Rails ("Edge" is the latest committed but unreleased version, so it usually works but may not be 100% production quality yet).

  4. Look into using namespaces in routes.rb - allocating an item within app to a namespace means you can put it into a subdirectory within the relevant app subdirectory, although this is perhaps less clean to having a separate set of Rails directories for each "application".

Of these, I have no experience of (2) because I'm tied (in infrastructure terms) to Rails, but that's OK, I like Rails. I'm planning to take look at (1) and maybe (3), because 2.3 may be released before I need to deploy my next major release, and I've tried (4), which works but is, well, fiddly and a little (to me) confusing.

Mike Woodhouse
We've gone to Merb for one of our projects specifically for slices. It works reasonably well. I'm curious what will happen in the Rails 3 merge.
Otto
Somehow, I'd overlooked (or forgotten) the engine plugin until I stumbled across it again today. Now I need to find some time over the holidays to assess whether I can get what I want from it. Ho hum. Or ho ho ho humbug?
Mike Woodhouse
+2  A: 

If you want to investigate Mike's #2 option, Merb slices there's a screencast on the topic that is helpful.

Otto
+2  A: 

I have used the desert plugin (formerly 'plugins plus'). It seems to work pretty well. http://github.com/pivotal/desert/tree/master