# Subdomain

**URL:** <https://www.ruby-forum.com/t/subdomain/95692>\
**Category:** Rails\
**Created:** [June 9, 2006, 1:55pm UTC](https://www.ruby-forum.com/t/subdomain/95692 "2006-06-09T13:55:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 9, 2006, 1:55pm UTC](https://www.ruby-forum.com/t/subdomain/95692/1 "2006-06-09T13:55:16Z")

</div>

I know how to retrieve the current :controller and :action, but is there  
a  
variable available for me to retrieve the URL items such as:

[subdomain.mydomain.com](http://subdomain.mydomain.com)

I would like to be able to pull “subdomain” out of the URL. Is this  
possible with something built-in?

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 9, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/subdomain/95692/2 "2006-06-09T14:01:17Z")

</div>

David wrote:

> I would like to be able to pull “subdomain” out of the URL. Is this  
> possible with something built-in?

[http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-routing-plugin](http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-routing-plugin)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 9, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/subdomain/95692/3 "2006-06-09T14:01:32Z")

</div>

You might want to look into acts\_as\_subdomainable 🙂 Just kidding,  
but you might look into this plugin:

[http://www.agilewebdevelopment.com/plugins/account\_location](http://www.agilewebdevelopment.com/plugins/account_location)

It probably has the goods to get you going.

Michael

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [June 9, 2006, 2:53pm UTC](https://www.ruby-forum.com/t/subdomain/95692/4 "2006-06-09T14:53:29Z")

</div>

“David” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…  
I know how to retrieve the current :controller and :action, but is there  
a  
variable available for me to retrieve the URL items such as:

[subdomain.mydomain.com](http://subdomain.mydomain.com)

@request.subdomains will give you an array of all the subdomains. In the  
example you gave, @request.subdomains.first would return “subdomain”
