In my Rails application I need to convert Strings like
Friedrichtraße 123, Berlin, Germany
into URLs like
Friedrichstra%C3%9Fe+123,+Berlin,+Germany
How can this be done in Ruby?
Thanks for any help.
In my Rails application I need to convert Strings like
Friedrichtraße 123, Berlin, Germany
into URLs like
Friedrichstra%C3%9Fe+123,+Berlin,+Germany
How can this be done in Ruby?
Thanks for any help.
require 'uri'
URI::encode("Friedrichtraße 123, Berlin, Germany")
#=> "Friedrichtra%C3%9Fe%20123,%20Berlin,%20Germany"
require 'cgi'
CGI.escape('Friedrichtraße 123, Berlin, Germany')
# => "Friedrichtra%C3%9Fe+123%2C+Berlin%2C+Germany"
To the two sub-Rails answers I will add: Invoke rake routes
, read in the first column the helper prefix of the URL you want - let's call it home
- then pack your variables as hash options into home_path
:
home_path(:address => 'Friedrichtraße 123, Berlin, Germany')