Q:

How to encode Email if it contains "+" to %2B in Ruby

How to encode URL parameters with UTF8 encoding:
URL?email=test+@gmail.com to URL?email=test%2B@gmail.com
I tried 'test+@gmail.com'.encode("UTF-8")
CGI::escape('test+@gmail.com') it returns 'test%2B%40gmail.com But i need test%2B@gmail.com
email=test+@gmail.com should encode to "+"only rest remain same
URL?email=test%2B@gmail.com

A:

The uri std-lib has a method for that URI::Escape#escape. URI extends the URI::Escape module, so also has this method.
URI.escape('test+@gmail.com', '+')
#=> "test%2B@gmail.com"        ^ the characters to escape with URL encoding

However like @spickermann says in the comments: 

Why do you want to encode the + in the URL but not the @? @ must be encoded too.

