# Multiple Sites, One Rails App

**URL:** <https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239>\
**Category:** Rails\
**Created:** [January 4, 2006, 2:35am UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239 "2006-01-04T02:35:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [January 4, 2006, 2:35am UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239/1 "2006-01-04T02:35:46Z")

</div>

Here is the situation: We have one rails app that is built around our  
fairly large DB. Since we have many models and logic inside those  
models, it makes sense for us to build only one rails app and share it  
among several different sites (Public web site, internal data backend,  
etc).

The thing I can’t quite get my head around is how to forward requests  
(using lighty) from different domains to top level controllers within  
the rails app:

Example:

[mysite.com](http://mysite.com) → site controller  
[data.mysite.com](http://data.mysite.com) → data controller

etc… The productize plugin seems to be overkill, as we aren’t extending  
the app or using different DBs for the different domains. Any thoughts?

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [January 4, 2006, 8:56am UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239/2 "2006-01-04T08:56:39Z")

</div>

Brad D. wrote:

> Here is the situation: We have one rails app that is built around our  
> fairly large DB. Since we have many models and logic inside those  
> models, it makes sense for us to build only one rails app and share it  
> among several different sites (Public web site, internal data backend,  
> etc).
> 
> The thing I can’t quite get my head around is how to forward requests  
> (using lighty) from different domains to top level controllers within  
> the rails app:
> 
> Example:
> 
> [mysite.com](http://mysite.com) → site controller  
> [data.mysite.com](http://data.mysite.com) → data controller
> 
> etc… The productize plugin seems to be overkill, as we aren’t extending  
> the app or using different DBs for the different domains. Any thoughts?  
> You could do something like:  
> before\_filter { |c| redirect\_to :controller=\>  
> c.request.subdomains.first, :action =\> ‘index’ }

This is untested by they way,but it should work.

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [January 4, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239/3 "2006-01-04T21:50:30Z")

</div>

Found a good solution (I think) 🙂

Instead of trying to consolidate into one app, I have kept the three  
separate rails apps that we have so far. However, with the two apps that  
build off of the main app’s model structure, I have emptied their models  
folder. Then, in their environments.rb file, I have added the  
following…

config.load\_paths += %W( /home/www/data/app/models )

This way, these apps can directly load the models from the main app, but  
still retain their individuality. Working great so far, just have to  
figure out a way to work with it locally…

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [September 27, 2006, 10:16pm UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239/4 "2006-09-27T22:16:07Z")

</div>

Hi Brad, did you ever figure out a way to make this work locally?

Brad D. wrote:

> Found a good solution (I think) 🙂
> 
> Instead of trying to consolidate into one app, I have kept the three  
> separate rails apps that we have so far. However, with the two apps that  
> build off of the main app’s model structure, I have emptied their models  
> folder. Then, in their environments.rb file, I have added the  
> following…
> 
> config.load\_paths += %W( /home/www/data/app/models )
> 
> This way, these apps can directly load the models from the main app, but  
> still retain their individuality. Working great so far, just have to  
> figure out a way to work with it locally…

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [September 28, 2006, 12:40am UTC](https://www.ruby-forum.com/t/multiple-sites-one-rails-app/89239/5 "2006-09-28T00:40:08Z")

</div>

There is a routing request plugin that should work here. Make sure to  
check it’s read me file.

Bill
