Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace space with %20 in rails [duplicate]

What I do

str= "  John   Smith Beer "
str.tr(" ", "%20")
"%%John%%%Smith%Beer%"

It doesn't replace it with "%20". How to fix it?

like image 911
Haseeb Ahmad Avatar asked Jan 06 '16 08:01

Haseeb Ahmad


1 Answers

require 'uri'
URI.encode("green books")
# => "green%20books"
like image 147
MilesStanfield Avatar answered Nov 10 '22 16:11

MilesStanfield