# Subdomain fu woes

**URL:** <https://www.ruby-forum.com/t/subdomain-fu-woes/154006>\
**Category:** Rails\
**Created:** [November 24, 2008, 3:23pm UTC](https://www.ruby-forum.com/t/subdomain-fu-woes/154006 "2008-11-24T15:23:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 24, 2008, 3:23pm UTC](https://www.ruby-forum.com/t/subdomain-fu-woes/154006/1 "2008-11-24T15:23:33Z")

</div>

I’m using subdomain\_fu successfully and generating subdomain routes  
like this:

rotues.rb:  
map.city\_root ‘’,:controller =\> ‘cities’, :action =\>  
‘index’, :conditions =\> { :subdomain =\> /.+/ }

using it in a view:  
\<%= link\_to city.name, city\_root\_path(:subdomain =\> city.subdomain)%\>

that works well, now I can’t figure out how to generate a nested route  
with subdomain,  
i.e. [miami.site.com/users/1](http://miami.site.com/users/1)

trying any combination of the form user\_path(@user,:subdomain =\>  
city.subdomain) does nothing excepnt append a parameter at the end of  
the url like this:

[site.com/users/1?subdomain=miami](http://site.com/users/1?subdomain=miami)

help is greatly appreciated guys!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 24, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/subdomain-fu-woes/154006/2 "2008-11-24T16:04:55Z")

</div>

Found the fix, it is a bug with the subdomain\_fu plugin.

the solution may be found here

[http://www.portallabs.com/blog/2008/10/22/fixing-subdomain\_fu-with-named-routes/](http://www.portallabs.com/blog/2008/10/22/fixing-subdomain_fu-with-named-routes/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 24, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/subdomain-fu-woes/154006/3 "2008-11-24T20:52:12Z")

</div>

On Nov 24, 2008, at 6:22 AM, removed\_email\_address@domain.invalid wrote:

> that works well, now I can’t figure out how to generate a nested route  
> with subdomain,  
> i.e. [miami.site.com/users/1](http://miami.site.com/users/1)
> 
> trying any combination of the form user\_path(@user,:subdomain =\>  
> city.subdomain) does nothing excepnt append a parameter at the end of  
> the url like this:
> 
> [site.com/users/1?subdomain=miami](http://site.com/users/1?subdomain=miami)

In addition to the fix you found, you may also want to check out this  
patch.

[http://rails.lighthouseapp.com/projects/8994/tickets/1115-path-to-extend-named-routes-support-for-an-objects-to\_params-method](http://rails.lighthouseapp.com/projects/8994/tickets/1115-path-to-extend-named-routes-support-for-an-objects-to_params-method)

I wrote that because of a recent site I built with 18 subdomains and  
not wanting to write out all those links by hand.

In your case above you could define a to\_params method on User to  
return the hash (including the subdomain) and then just do  
user\_path(@user) and it will do the right thing.

Anyway, see the ticket for more info.

-philip
