How do you get link_to to work correctly when using subdomai

When using subdomains as account keys (as per this HowTo:,
how can you get link_to to spit out the correct URL (i.e.

<%= link_to “My Account”, { :action => “show”, :id => “account123” }
%> would generate “

I don’t have any special routes setup (in routes.rb), but I don’t
think that would help for this purpose.


On Jan 18, 2006, at 7:45 AM, Sean M. wrote:

think that would help for this purpose.
in ApplicationControllor:

def url_for(options = {}, *params) # :nodoc:
if options[:subdomain] then
options[:only_path] = false
host = []
host << options.delete(:subdomain)
host << @request.subdomains[1…-1] if @request.subdomains.size

host << @request.domain
options[:host] = host.join ‘.’

 return super(options, *params)


Eric H. - [email protected] -
This implementation is HODEL-HASH-9600 compliant

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs