I thought Rails would do it for you. But if you need to do this manually, you can use CGI :: escape, for example.
> require 'cgi' ... > CGI.escape("hello%there\nworld") => "hello%25there%0Aworld"
EDIT: Actually, CGI doesn't seem to be evading the point. The URI can be used instead, it takes an additional parameter that allows you to specify additional characters that you want to escape:
URI.escape("hello.there%world", ".")
source share