URI::InvalidURIError with open-uri and Google Maps

Hello,

I'm getting an URI::InvalidURIError in my controller when I use german characters in the uri. Google accepts them but open-uri not. How to encode them?

That's my controller simplified:

def index   require 'open-uri'   address = "Bürgerstraße+68+01127+Dresden"   api_key = "my api key"   json = open("http://maps.google.com/maps/geo?q=#\{\(address\)\} &output=json&key=#{api_key}").read   render :text => json end

My environment: Rails 2.3.2 Gem 1.3.4 ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

Yours, Matthias.

Ok, I should precise my question. I know I have to encode the special charactes to ascci code. For js, java and php there is a function to convert the characters. I didn't found one for rails.

So is there a better way for converting then gsub for every single special char:? address = address.gsub(/ü/,'%FC')

Yours, Matthias.

Ok, I should precise my question. I know I have to encode the special charactes to ascci code. For js, java and php there is a function to convert the characters. I didn't found one for rails.

So is there a better way for converting then gsub for every single special char:? address = address.gsub(/ü/,'%FC')

Yours, Matthias.

URI.encode

http://www.ruby-doc.org/core/classes/URI/Escape.html

If it seems like something that should be a standard part of the language, it probably is: always check the docs first.