Skip to content

Instantly share code, notes, and snippets.

@swistaczek
Created September 1, 2012 12:42
Show Gist options
  • Save swistaczek/3572214 to your computer and use it in GitHub Desktop.
Save swistaczek/3572214 to your computer and use it in GitHub Desktop.
Create helper for :subdomain in Rails 3
# -*- encoding : utf-8 -*-
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
domain_woport = request.domain.gsub(/:{1}\d*/, '')
[subdomain, request.domain].join #request.port_string
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
options[:only_path] = false
end
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment