I was having some similar problems with routing to "/protégés/:id". I posted to the Rack mailing list, but the response wasn't great.
The solution I came up with isn't perfect, but it works for most cases. First, create a middleware that unencodes the UTF-8:
# in lib/fix_unicode_urls_middleware.rb:
require 'cgi'
class FixUnicodeUrlsMiddleware
ENVIRONMENT_VARIABLES_TO_FIX = [
'PATH_INFO', 'REQUEST_PATH', 'REQUEST_URI'
]
def initialize(app)
@app = app
end
def call(env)
ENVIRONMENT_VARIABLES_TO_FIX.each do |var|
env[var] = CGI.unescape(env[var]) if env[var] =~ /%[A-Za-z0-9]/
end
@app.call(env)
end
end
Then use that middleware in your config/environment.rb
(Rails 2.3) or config/application.rb
(Rails 3).
You'll also have to ensure you've set the right encoding HTTP header:
Content-type: text/html; charset=utf-8
You can set that in Rails, in Rack, or in your web server, depending on how many different encodings you use on your site.