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.
Ae577905a543a759b11ce883ffd00ef6?d=identicon&s=25 Sean Mountcastle (Guest)
on 2006-01-18 17: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.

58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-01-18 19:58
(Received via mailing list)
On Jan 18, 2006, at 7:45 AM, Sean Mountcastle 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 Hodel - -
This implementation is HODEL-HASH-9600 compliant
This topic is locked and can not be replied to.