# RESTful routes and subdomains

**URL:** <https://www.ruby-forum.com/t/restful-routes-and-subdomains/127437>\
**Category:** Rails\
**Created:** [January 29, 2008, 6:30am UTC](https://www.ruby-forum.com/t/restful-routes-and-subdomains/127437 "2008-01-29T06:30:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 6:30am UTC](https://www.ruby-forum.com/t/restful-routes-and-subdomains/127437/1 "2008-01-29T06:30:41Z")

</div>

I am looking for a way to use RESTful routes, but include the ability to  
add the required subdomain to the url.

I have found a couple plugins, but they don’t allow for the RESTful  
routes.

Does anyone know of any?

Thanks

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 10:36am UTC](https://www.ruby-forum.com/t/restful-routes-and-subdomains/127437/2 "2008-01-29T10:36:22Z")

</div>

On 29 Jan 2008, at 06:30, Chris O. wrote:

> I am looking for a way to use RESTful routes, but include the  
> ability to  
> add the required subdomain to the url.
> 
> I have found a couple plugins, but they don’t allow for the RESTful  
> routes.
> 
> Does anyone know of any?

Why wouldn’t account\_location allow you to use RESTful routes?

You just check the subdomain in a before\_filter (if you’re using it  
as a way of determining the customer account) and the rest is exactly  
the same as working on a normal website without subdomain  
authentication.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/restful-routes-and-subdomains/127437/3 "2008-01-29T18:05:50Z")

</div>

I don’t think my question was very clear. I am confused how to include  
the subdomain in the routing method call.

ex

# redirect the user to the account cpanel for their subdomain

redirect\_to account\_url #this url will not include the proper  
subdomain.

After checking out the account\_location lib file it can be seen that the  
equivalent can be done with:  
redirect\_to :host =\> account\_host(@account.subdomain), :controller =\>  
“account”

The downfall is that I am unable to use the routing methods.

But, as you mentioned, when accessing the subdomain within a controller  
it is easy to do so by having a before\_filter that extracts it from the  
request.subdomains array.
