# Seeking Advice on Pattern for Multi-Organization Application

**URL:** <https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743>\
**Category:** Rails\
**Created:** [July 1, 2006, 11:25am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743 "2006-07-01T11:25:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 1, 2006, 11:25am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/1 "2006-07-01T11:25:51Z")

</div>

I am the developer of FreeMIS - an Open Source management information  
system for schools. It currently holds the data for one school - so  
different schools host different instances of FreeMIS.

I would like to expand the domain of a single instance of FreeMIS, so  
that it covers all the schools in an education authority. THis will  
enable me to implement authority-wide functionality.

Is there a standard pattern for this kind of extension? As I see it,  
everything that is in the database will need also to belong to a school,  
and when someone logs in they will only see the data relevant to their  
school (unless they are education authority managers who will have their  
own interface).

Any advice on how to implement this in the DRYest, most Rails-esque way  
will be most gratefully received 🙂

Robert J.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 1, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/2 "2006-07-01T16:37:08Z")

</div>

On Jul 1, 2006, at 18:25 , Robert J. wrote:

> I would like to expand the domain of a single instance of FreeMIS, so  
> that it covers all the schools in an education authority. THis will  
> enable me to implement authority-wide functionality.

Sounds like what you want is an Authority model that  
has\_many :schools. I don’t think you want a separate database for  
each school.

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 1, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/3 "2006-07-01T20:20:45Z")

</div>

On Jul 1, 2006, at 2:25 AM, Robert J. wrote:

> school,
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

You should have a look at the acount\_location plugin. Its built for  
this situation. It allows you to have accounts keyed off of  
subdomains. like [foo.example.com](http://foo.example.com) and [bar.example.com](http://bar.example.com). This way you  
have an Account model and you use a before filter on every request  
that takes the subdomain and finds the account that matches that  
subdomain. Then you scope your queries to the account model.

-Ezra

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 2, 2006, 3:32am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/4 "2006-07-02T03:32:22Z")

</div>

On 7/2/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > enable me to implement authority-wide functionality.  
> > way
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

With the account\_location plugin, does it automatically setup the  
required  
DNS entries? Or does an app need to look after this itself?   
This is a very weak point for me, and has basically stopped me from  
looking  
at it too closely.

Dan

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 2, 2006, 3:44am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/5 "2006-07-02T03:44:41Z")

</div>

On Jul 1, 2006, at 6:30 PM, Daniel N wrote:

> > 
> 
> their
> 
> > –  
> > that takes the subdomain and finds the account that matches that  
> > required DNS entries? Or does an app need to look after this  
> > itself?   
> > This is a very weak point for me, and has basically stopped me from  
> > looking at it too closely.
> 
> Dan

Dan-

```
Yeah you have to set up a wildcard dns entry for your domain in

```

order to use this in production. But you can set up aliases in /etc/  
hosts for when you are developing locally.

for local stuff ad a line like this to your /etc/hosts file:

127.0.0.1 [advisrdev.org](http://advisrdev.org) [ezmobius.advisrdev.org](http://ezmobius.advisrdev.org) [demo.advisrdev.org](http://demo.advisrdev.org)

That gives me a few subdomains and a main domain to work with locally.

-Ezra

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 2, 2006, 3:54am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/6 "2006-07-02T03:54:00Z")

</div>

On 7/2/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > school,  
> > > Robert J.  
> > > subdomains. like [foo.example.com](http://foo.example.com) and [bar.example.com](http://bar.example.com). This way you
> 
> Dan-
> 
> -Ezra

Thanx for the response, but I’m afraid I’m a bit thick with this stuff.  
I  
can see what you’ve done in the /etc/hosts file wrt local requests, is  
it  
enough to add to the hosts file on the server in a live app for external  
users to have their browsers do the right thing or does it need to  
update a  
dns server?

Basecamp seems to have their accounts available on subdomains  
immediatley  
when you sign up so I don’t imagine that they have to propergate this  
change  
though the net DNS system.

Is there anywhere that gives a fairly in-depth explaination or tutorial  
that’s not quite as dry as a DNS spec?

Cheers  
Dan

Thanx for any help

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 2, 2006, 4:37am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/7 "2006-07-02T04:37:05Z")

</div>

On Jul 1, 2006, at 6:53 PM, Daniel N wrote:

> > On Jul 1, 2006, at 2:25 AM, Robert J. wrote:  
> > will
> > 
> > > own interface).  
> > > Rails mailing list
> > 
> > from looking at it too closely.  
> > for local stuff ad a line like this to your /etc/hosts file:  
> > requests, is it enough to add to the hosts file on the server in a  
> > Cheers  
> > Dan
> 
> Thanx for any help

Dan-

```
Yeah you need to set up what's called a wildcard dns A record. This

```

looks like \*.mydomain.com. What dns server are you using? Here is a  
nice tutorial for bind, not rails specific but it should help anyway.

> **[Wildcard DNS and Sub Domains](https://ma.tt/2003/10/wildcard-dns-and-sub-domains/)**
>
> 383 and 384

-Ezra

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 3, 2006, 10:09am UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/8 "2006-07-03T10:09:20Z")

</div>

Ezra Z. wrote:

> On Jul 1, 2006, at 2:25 AM, Robert J. wrote:
> 
> > school,
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> You should have a look at the acount\_location plugin. Its built for  
> this situation. It allows you to have accounts keyed off of  
> subdomains. like [foo.example.com](http://foo.example.com) and [bar.example.com](http://bar.example.com). This way you  
> have an Account model and you use a before filter on every request  
> that takes the subdomain and finds the account that matches that  
> subdomain. Then you scope your queries to the account model.
> 
> -Ezra

Thanks for this (and for the other advice by other people) - this looks  
like just what I need. The scoping of my queries to the account model  
is going to take a while, but I know where I’m heading now.

Cheers,

Robert J.

---

<div class="post-metadata">

**Author:** ![robertjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9c0ed/32.png) [@robertjames](https://www.ruby-forum.com/u/robertjames)\
**Post date:** [July 5, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/seeking-advice-on-pattern-for-multi-organization-application/96743/9 "2006-07-05T14:39:03Z")

</div>

On 7/2/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > different schools host different instances of FreeMIS.  
> > > > and when someone logs in they will only see the data relevant to
> > > 
> > > have an Account model and you use a before filter on every request
> > 
> > -Ezra  
> > though the net DNS system.  
> > Dan-
> 
> Yeah you need to set up what’s called a wildcard dns A record. This looks  
> like \*.mydomain.com. What dns server are you using? Here is a nice tutorial  
> for bind, not rails specific but it should help anyway.
> 
> [Wildcard DNS and Sub Domains | Matt Mullenweg](http://photomatt.net/2003/10/10/wildcard-dns-and-sub-domains/)
> 
> -Ezra

Ezra,

Thanx for the pointer. Being on windows it took me a while to get it  
going… Eventually got it with the treewalk dns server.

Cheers  
Dan
