I’ve been experimenting with using radiant to host multiple sites. The
approach I was taking was to have, say, a mongrel_cluster that could
host
a lot of different sites, and instead of having a mongrel_cluster (or
even
just a single mongrel instance) per site, I wanted to have a pool of
mongrels for all of the hosted sites. So for example, if I was hosting
15
different sites I wouldn’t have to have 15 mongrel instances, but I
could
have 7 or 8 mongrel instances that multiplex between the 15 sites.
Here’s what I’ve come up with, drop this into
vendor/plugins/multisite/init.rb:
require ‘application’
require ‘response_cache’
ApplicationController.prepend_before_filter Proc.new {|controller|
ActiveRecord::Base.establish_connection controller.request.host
controller.cache.directory =
File.join(ActionController::Base.page_cache_directory,
controller.request.host) if controller.respond_to?(:cache)
ActionController::Base.session_options[:session_key] =
controller.request.host
}
What I’m doing is changing the database connection, cache directory, and
session key per request, based upon the host that is being used for the
request. In order for this to work you have to have a database named
after each hostname (i.e. example1.com, example2.com) and defined in the
database.yml file. It seems to work well enough, but when I login to
the
admin site for example1.com, and then go to the admin site for
example2.com, and then browse back to the admin site for example1.com, I
get the login page, but the Pages, Snippets and Layouts tabs appear at
the
top. I can click on the Pages tab and go back to editing pages, which
is
what I would expect since I am logged in to both sites. In fact, even
if
I log in to one site and just hit the login screen for the other
(without
logging in) the same behavior occurs.
I’m not sure why the login screen comes up. Apparently I’m being
redirected to the login screen, which renders the navigation bar,
because
:logged_in? in the ApplicationHelper is returning true.
Perhaps I’m going about this the wrong way. Has anyone done anything
similar? Any comments?
Paul