How do you get link_to to work correctly when using subdomai


#1

When using subdomains as account keys (as per this HowTo:
http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys),
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


#2

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 ‘.’
end

 return super(options, *params)

end


Eric H. - removed_email_address@domain.invalid - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com