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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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:
http://wiki.rubyonrails.org/rails/pages/HowToUseSu...),
how can you get link_to to spit out the correct URL (i.e.
account123.domain.com)?

<%= link_to "My Account", { :action => "show", :id => "account123" }
%> would generate "http://www.domain.com/show/account123"

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

Thanks,
Sean
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 '.'
     end

     return super(options, *params)
   end

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
This topic is locked and can not be replied to.