Try out the awesome gem Domainatrix:
Then you can simply parse the URL on the fly with:
<%= Domainatrix.parse(@user.url).url %>
Better yet, create a before_save action in your user model that parses the url before saving it.
before_save :parse_url
def parse_url
if self.url
self.url = Domainatrix.parse(self.url).url
end
end
Here are some samples of what you can do with Domainatrix:
url = Domainatrix.parse("http://www.pauldix.net")
url.url # => "http://www.pauldix.net" (the original url)
url.public_suffix # => "net"
url.domain # => "pauldix"
url.canonical # => "net.pauldix"
url = Domainatrix.parse("http://foo.bar.pauldix.co.uk/asdf.html?q=arg")
url.public_suffix # => "co.uk"
url.domain # => "pauldix"
url.subdomain # => "foo.bar"
url.path # => "/asdf.html?q=arg"
url.canonical # => "uk.co.pauldix.bar.foo/asdf.html?q=arg"