Created
August 12, 2013 19:40
-
-
Save TXDynamics/6214363 to your computer and use it in GitHub Desktop.
Rails helper that extracts the domain from a URL submitted to the function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use this helping to display the base domain name of a url | |
# I am using it when displaying web results that are loaded from Social Search | |
def get_host_without_www(url) | |
require 'uri' | |
uri = URI.parse(url) | |
uri = URI.parse("http://#{url}") if uri.scheme.nil? | |
host = uri.host.downcase | |
host.start_with?('www.') ? host[4..-1] : host | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment