Ultimately what I need to make happen is have two domains point to the
same application, however depending on which domain is accessing it to
use a different database.
I suggested installing the application on two servers, but that option
is for some reason not good. I tried to install the application twice
into one account and just symlink them depending on the domain but
that did not work either, here's why:
One domain has to point to ~/public_html, I have no option in that the
way our host is set up. The second domain has to point to a
subdirectory of ~/public_html. Adding a symlink to the first
application's public folder didn't work because Apache is unable to
follow through two symlinks.
Adding any extra characters to the URL is out of the question too, so
I can't use domain.com/i/app
Ultimately I just need the question answered that is at the top, any
takers?
What about having two separate checkouts in the same machine, each with its own database.yml. Configure a virtual host for each one in Apache. Each virtual host then has its own document root and mongrel cluster (each instance of the application runs behind its own cluster).
Careful, with that approach MyModel will always point to the database of the domain that triggered its class loading. In development mode that works because the class is reloaded at each request. However, in production mode that means MyModel won't point to the table of the database of the other domain _ever_.
If that's OK then you have your model layer really partitioned in two databases known before hand, and in that case the regular establish_connection + two keys in database.yml will suffice.
Otherwise you'd move that code to a high-priority filter in ApplicationController:
def choose_database_for_host
ActiveRecord::Base.establish_connection ...
end
because you need to select the connection _per request_. That has a performance cost, but perhaps it's fine with the load of that applicaction. If that was not the case more intrusive solutions involving some sort of connection pool would be needed.
-- fxn
PS: The solution with two separate checkouts with respective mongrel clusters didn't fit?