# Subdomain Account Keys Best Practice

**URL:** <https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047>\
**Category:** Rails\
**Created:** [January 17, 2007, 12:56am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047 "2007-01-17T00:56:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [January 17, 2007, 12:56am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047/1 "2007-01-17T00:56:19Z")

</div>

Hi all,

I’m thinking of useing sub-domains as account keys, something I’ve  
played  
with previously.

I have accounts and users, fairly standard, except that users can belong  
to  
many accounts, and accounts can have many users.

So I figure I need to have an area on the main domain, that allows users  
to  
view their account memberships and things. Sort of like a dashboard for  
each user. When they login without a sub domain, all their membership  
informaition, and cross-account information ( eg todo’s for all accounts  
)  
would be available. When they log in with a sub domain, all information  
is  
scoped to the account.

Is this thinking fraught with danger? or reasonably sane?

Thanx for any insights.

Daniel

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [January 17, 2007, 3:41am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047/2 "2007-01-17T03:41:37Z")

</div>

On 1/16/07, Daniel N [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> each user. When they login without a sub domain, all their membership
> 
> >

Daniel,

What you’re describing can be done without much trouble. I use a  
similar model at [trackplace.com](http://trackplace.com). Just set aside some domains:

# environment.rb

RESERVED\_SUBDOMAINS = %w(  
www www1 www2 www3 www4 www5 www6 www7 www8 www9 www10 web  
app app1 app2 app3 app4 app5 app6 app7 app8 app9 app10  
db db1 db2 db3 db4 db5 database  
blog blogs weblog public private secure store stores help admin  
admins  
mail email emails root postmaster postmasters friend friends  
test testing dev marketing search profile profiles group groups  
forum forums  
)

# account.rb

validates\_exclusion\_of :subdomain, :in =\> RESERVED\_SUBDOMAINS,  
:message =\> ‘Web site name is reserved.’

Set aside a subdomain like ‘profile’ or ‘membership’ to handle  
membership stuff and the request\_routing plugin to handle routing by  
subdomain.

Hope this helps,

–  
Zack C.  
[http://depixelate.com](http://depixelate.com)  
[http://trackplace.com](http://trackplace.com)

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [January 17, 2007, 3:49am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047/3 "2007-01-17T03:49:39Z")

</div>

On 1/17/07, Zack C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> www www1 www2 www3 www4 www5 www6 www7 www8 www9 www10 web
> 
> ```
> 
> :message =\> ‘Web site name is reserved.’
> 
> Set aside a subdomain like ‘profile’ or ‘membership’ to handle  
> membership stuff and the request\_routing plugin to handle routing by  
> subdomain.

Hi Thanx for your input.

I’m not sure I understand what the request\_routing plugin would be doing  
here.

Also what benefit is using a special sub-domain over the base domain?

Cheers

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [January 17, 2007, 4:06am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047/4 "2007-01-17T04:06:40Z")

</div>

On 1/17/07, Zack C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > What you’re describing can be done without much trouble. I use a  
> > > test testing dev marketing search profile profiles group groups  
> > > subdomain.
> 
> The request\_routing plugin allows you to route off of additional
> 
> [members.example.com](http://members.example.com) # =\> the area you want to provide to handle profiles
> 
> This is one way to do it…
> 
> Or a scheme like:
> 
> [john.example.com/profile](http://john.example.com/profile)
> 
> probably makes more sense.

Ok I think I see what you mean. I’ll give it a try.

Thanx for you help

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [January 17, 2007, 4:01am UTC](https://www.ruby-forum.com/t/subdomain-account-keys-best-practice/82047/5 "2007-01-17T04:01:40Z")

</div>

On 1/16/07, Daniel N [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # environment.rb
> > 
> > # account.rb
> 
> here.
> 
> Also what benefit is using a special sub-domain over the base domain?
> 
> Cheers
> 
> >

Daniel,

You said “… I need to have an area on the main domain, that allows  
users to view their account memberships and things…”

The request\_routing plugin allows you to route off of additional  
conditions like the subdomain:

# routes.rb

map.with\_options(:controller =\> ‘users’, :conditions =\> { :subdomain  
=\> ‘members’ }) do |url|  
url.profile ‘’  
url.change\_password ‘change\_password’, :action =\>  
‘change\_password’  
…  
end

[members.example.com](http://members.example.com) # =\> the area you want to provide to handle profiles

This is one way to do it…

Or a scheme like:

[john.example.com/profile](http://john.example.com/profile)

probably makes more sense.

–  
Zack
