I ve追随可在上查阅。
It allows you to pass a subdomain option to your routes by overriding the url_for method in a helper file. I ve helper method looks like this:
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
end
因此:
sites_homepage_url(:subdomain => "cats")
生产:
"http://cats.example.com/sites/1/homepage"
这种做法在发展中是值得称道的。 然而,在我的黄瓜试验中,使用了:
sites_homepage_url(:subdomain => "cats")
生产:
"http://www.example.com/sites/1/homepage?subdomain=cats"
这表明,我为帮助者工作而增加了尿素。 没有人会提出想法?
Edit: Formatting and supplemented the Code for the UrlHelper.