Skip to content

Instantly share code, notes, and snippets.

@welingtonsampaio
Created May 7, 2013 16:02
Show Gist options
  • Save welingtonsampaio/5533777 to your computer and use it in GitHub Desktop.
Save welingtonsampaio/5533777 to your computer and use it in GitHub Desktop.
Method for create url with subdomain
def with_subdomain(subdomain)
subdomain = (subdomain || "").to_s
subdomain += "." unless subdomain.empty?
domain=request.domain.gsub! /^(\w){2}\./, ""
[subdomain, domain].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
options[:port] = request.port_string.gsub(':','') unless request.port_string.empty?
end
super
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment