# How to use subdomains to represent sections?

**URL:** <https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169>\
**Category:** Rails\
**Created:** [June 7, 2007, 1:52am UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169 "2007-06-07T01:52:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 7, 2007, 1:52am UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169/1 "2007-06-07T01:52:31Z")

</div>

I have a website that has 3 main sections:

1. Tickets
2. Company (About Us)
3. Admin

I would prefer to use subdomains for these sections:  
[tickets.whatever.com](http://tickets.whatever.com), [company.whatever.com](http://company.whatever.com)

The problem though is that I need a specific set of controllers for each  
section. I dont want to do [tickets.whatever.com/tickets/some\_controller](http://tickets.whatever.com/tickets/some_controller).  
It kind of defeats the purpose of a subdomain.

Any ideas?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 7, 2007, 3:45am UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169/2 "2007-06-07T03:45:25Z")

</div>

On Jun 7, 2:52 am, Ben J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have a website that has 3 main sections:
> 
> 1. Tickets
> 2. Company (About Us)
> 3. Admin
> 
> I would prefer to use subdomains for these sections:  
> [tickets.whatever.com](http://tickets.whatever.com), [company.whatever.com](http://company.whatever.com)  
> This should be done with routes. You have to rewrite routes and  
> url\_for a bit. And don’t forget to set  
> ActionController::Base.session\_options[:session\_domain] to  
> “.whatever.com”  
> I don’t think in your case you’ll benefit much from using subdomains,  
> but it’s only up to to decide whether to spend decent amount of time  
> hacking ActionController::Routing to and  
> ActionView::Helpers::UrlHelper to map things back and forth, or rest  
> happy with default routing.

> The problem though is that I need a specific set of controllers for each  
> section. I dont want to do [tickets.whatever.com/tickets/some\_controller](http://tickets.whatever.com/tickets/some_controller).  
> Does it means ‘tickets’ is module in your setup, like in  
> Tickets::SomeTicketsController#action\_on\_ticket?  
> You don’t need it anyway, TicketsController filled with tickets  
> related actions is enough.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 7, 2007, 9:25am UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169/3 "2007-06-07T09:25:30Z")

</div>

On 07 Jun 2007, at 01:52, Ben J. wrote:

> each  
> section. I dont want to do [tickets.whatever.com/tickets/](http://tickets.whatever.com/tickets/)  
> some\_controller.  
> It kind of defeats the purpose of a subdomain.

You should use the request\_routing plugin from Dan W…

[http://agilewebdevelopment.com/plugins/request\_routing](http://agilewebdevelopment.com/plugins/request_routing)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 7, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169/4 "2007-06-07T16:20:31Z")

</div>

> You should use the request\_routing plugin from Dan W…
> 
> [http://agilewebdevelopment.com/plugins/request\_routing](http://agilewebdevelopment.com/plugins/request_routing)

> > I dont want to do [tickets.whatever.com/tickets/some\_controller](http://tickets.whatever.com/tickets/some_controller)  
> > This requirement makes request\_routing inappropriate.  
> > Ben asking for mapping subdomain to controller name, while  
> > request\_routing provides a way to include subdomain in mapping  
> > requirements.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 7, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/how-to-use-subdomains-to-represent-sections/106169/5 "2007-06-07T20:28:17Z")

</div>

Actually, using the request\_routing plugin is a good idea, as it  
allows you to map to different controllers based on subdomain. I use  
it for exactly that purpose myself.

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/) – blog  
[http://agilewebdevelopment.com/rails-ecommerce](http://agilewebdevelopment.com/rails-ecommerce) – build e-commerce  
sites with Rails
