Multiple apps, one domain

Courtenay : October 17th, 2007

Sometimes you find yourself with eighty controllers and it becomes too large to fit in your head.

In this case, you may want to think about separating parts of your mega application into smaller applications. This will help your team work on different parts in parallel.

Unfortunately, routing doesn’t currently support this. While in most cases you’re only linking to index or show from another controller (you don’t really PUT or POST from another controller ) it still requires some kind of helper methods (def users_path ; “http://”.. ) or routing hack.

Jake Howerton has just published a plugin that hacks routes to solve just this problem: Multi App Routing Check it out. The module_eval stuff scares me, but then again, I just don’t want to understand the mechanics of routing.

Config is done with a yaml file, and the syntax looks like

map.application(:billing, :protocol => ‘https’) do |billing|
  billing.resources :payments
end

Nice and simple.

4 Responses to “Multiple apps, one domain”

  1. Scott Says:

    How do you set it up so that two apps connect to the same database? With respect to migrations, won't schema_info get all out of whack?

  2. dayne Says:

    Scott: You would pick one of your multiple apps to be the 'database admin' app. That one is where you would do all your migrations and such.

    You are right that you don't want multiple rails apps doing schema work on the same database.

  3. Josh Owens Says:

    Dayne and Scott,

    Actually, it doesn't matter if you have an admin or master db app. When a migration runs it looks at the migration number in the schema table. If it is already migrated to the highest number, it does nothing.

  4. Jimmy Schementi Says:

    @Josh

    It does matter, since the "migration" numbers won't be correct. If you add a migration to an app, then another to the other app, they will both be numbered 001. Which app's db:migrate do you run first? This especially matters when your modifying existing tables ... and is just asking for trouble.

    To keep it simple, just pick one app to create/run your migrations from.

Sorry, comments are closed for this article.