I had some similar problems with routing to "/ protégés /: id". I am sent to the Rack mailing list, but the answer was small.
The solution I came up with is not perfect, but it works in most cases. First, create a middleware that decodes UTF-8:
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 this middleware in config/environment.rb(Rails 2.3) or config/application.rb(Rails 3).
You also need to make sure that you set the correct HTTP encoding header:
Content-type: text/html; charset=utf-8
You can install this in Rails, in the rack or on your web server, depending on how many different encodings you use on your site.
source
share