Forum: Ruby on Rails How do you get link_to to work correctly when using subdomai

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sean M. (Guest)
on 2006-01-18 18:23
(Received via mailing list)
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.

Eric H. (Guest)
on 2006-01-18 20:58
(Received via mailing list)
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
 > 1
       host << @request.domain
       options[:host] = host.join '.'

     return super(options, *params)

Eric H. - removed_email_address@domain.invalid -
This implementation is HODEL-HASH-9600 compliant
This topic is locked and can not be replied to.