# Multisite Radiant

**URL:** <https://www.ruby-forum.com/t/multisite-radiant/67508>\
**Category:** Radiant CMS\
**Created:** [September 4, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/multisite-radiant/67508 "2006-09-04T19:54:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Stadig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@Paul\_Stadig](https://www.ruby-forum.com/u/Paul_Stadig)\
**Post date:** [September 4, 2006, 7:54pm UTC](https://www.ruby-forum.com/t/multisite-radiant/67508/1 "2006-09-04T19:54:05Z")

</div>

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](http://example1.com), [example2.com](http://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](http://example1.com), and then go to the admin site for  
[example2.com](http://example2.com), and then browse back to the admin site for [example1.com](http://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

---

<div class="post-metadata">

**Author:** ![Paul\_Stadig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@Paul\_Stadig](https://www.ruby-forum.com/u/Paul_Stadig)\
**Post date:** [September 5, 2006, 8:14pm UTC](https://www.ruby-forum.com/t/multisite-radiant/67508/2 "2006-09-05T20:14:17Z")

</div>

Not quite sure I follow your situation but one think to consider is auth  
cookies. Rails keeps a session using a cookie to identify your session.  
This  
cookie has a domain that it will work for. Whenever you change domains  
you  
will change cookies. For one project I have 15 sites all under one main  
domain ([a.dom.com](http://a.dom.com), [b.dom.com](http://b.dom.com), [c.dom.com](http://c.dom.com), etc) so I set my cookie domain  
to  
“.dom.com” and it worked for all sites. Not sure it helps…

AEM
