I'm accepting user input in the form of web links, e.g.: http://google.com
In my database I don't want to store the http://
prefix, or https://
. I was going to do a string search at the beginning of the URL for those two things.
I feel like this is something rails/ruby might do out of the box, does anyone know of such a function?
From the document:
require 'uri'
uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
uri.scheme #=> "http"
uri.host #=> "foo.com"
uri.path #=> "/posts"
uri.query #=> "id=30&limit=5"
uri.fragment #=> "time=1305298413"
Or,
require 'uri'
URI.split("http://www.ruby-lang.org/")
# => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With