# One Application, Multiple Domains.. separate data?

**URL:** <https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765>\
**Category:** Rails\
**Created:** [August 10, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765 "2007-08-10T16:48:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/1 "2007-08-10T16:48:52Z")

</div>

Hi,

I am developing a sort of CMS application that will be used by  
multiple domains on my host.

Each domain requires its own set of users, news, etc., but I would  
like to keep my application only installed one place on my host and  
sym-link to it.

Is it possible to modify all queries to also include a ‘domain’ in the  
where clause or something like that?

i.e. if i do a Table.find(:all) in one of my controllers, and that  
controller is being accessed by domain1, can I limit the query’s  
results by some sort of where clause?

I dabbled with the idea of using table prefix’s, but later ditched the  
idea.

It seems like the appropriate solution is to add another column to my  
tables that includes which domain the data is specific to and somehow  
limit that in the application… any ideas?

Thanks,  
jay

---

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/2 "2007-08-10T17:29:21Z")

</div>

Can’t you make multiple accounts like:

[http://myapp/user/1](http://myapp/user/1)  
is linked from [http://www.johndoe.com](http://www.johndoe.com)

and  
[http://myapp/user/2](http://myapp/user/2)  
is linked from [http://www.billybob.com](http://www.billybob.com)

(and only have table lookups for user/1 be for that user, etc.?)

like:

Table.find(:all, :conditions =\> [“user = ?”, params[:id]])

I’m no expert, but I have an application working that does the same  
thing - and I can’t remember if it’s simlinked or we did some other  
domain forwarding or what on the host to handle the multiple domain  
names…

---

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/3 "2007-08-10T19:05:09Z")

</div>

I guess this is possible, but I will have to look more into linking/  
forwarding.

For instance, [domain1.com/news/show/1](http://domain1.com/news/show/1) would need to tell the  
application to find the news with :id of 1, but ALSO where domain=1.

Can I link so that all urls also pass along an extra set of  
parameters?

-Jay

On Aug 10, 10:29 am, Dustin A. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/4 "2007-08-10T19:39:04Z")

</div>

Hi Jay,  
I’ve faced the same problem twice and once was for a project similar to  
yours. There are essentially to ways: 1)a unique base code and a unique  
db with a field identifying the customer in the tables; 2)a unique base  
code and multiple databases (one per customer). For the CMS project I  
followed the second way and the main problem is when you need to change  
the DB structure but I think rake could help you a lot. Having faced  
these problems and being working with PHP I then tried the first way but  
I’ve to tell you that the development is much slower since almost each  
query require to take in consideration the customer\_id. Furthermore as  
the db grows some queries get very slow so you have to tune them  
carefully. Should you use a single DB you may consider partitioning the  
DB which is available as of MySQL 5.1, that could help you make the  
queries faster.  
This is in summary my experience.  
After finishing the second project I finally found a document with a in  
depth discussion of these alternatives and … it’s published by M$,  
here’s the link: [Microsoft Learn: Build skills that open doors in your career](http://msdn2.microsoft.com/en-us/library/Aa479086.aspx)

Nik

---

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/5 "2007-08-10T19:30:45Z")

</div>

It might be useful to consider creating a different database instance  
for each client/domain and simply customizing the database entries in  
config/database.yml to suit. As I recall it is possible to place ruby  
code in there so you may even be able to automate the the custom  
configuration based on the incoming domain.

This also allows for clean separation of user data for backups, restores  
and service termination.

---

<div class="post-metadata">

**Author:** ![unreal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/3e96dc/32.png) [@unreal](https://www.ruby-forum.com/u/unreal)\
**Post date:** [August 10, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/one-application-multiple-domains-separate-data/111765/6 "2007-08-10T19:50:09Z")

</div>

unreal wrote:

> It seems like the appropriate solution is to add another column to my  
> tables that includes which domain the data is specific to and somehow  
> limit that in the application… any ideas?

Have you looked into a combination of account\_location and scope\_out  
plugins?

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.
