Reputation: 55
I have a string with URL data, ex: "http://www.amazon.com" and I would like to receive "http%3A%2F%2Famazon.com".
After reading different posts I am using this command:
irb(main):025:0> require 'open-uri'
=> true
irb(main):026:0> URI.encode("http://www.amazon.com")
=> "http://www.amazon.com"
irb(main):027:0>
As you can see I receive my string instead of "http%3A%2F%2Famazon.com".
I really appreciate your help and time.
Upvotes: 0
Views: 92
Reputation: 53038
Use
CGI.escape("http://www.amazon.com")
#=> "http%3A%2F%2Fwww.amazon.com"
Upvotes: 4