4

in my routes.rb I have the follow route:

get '/merchandises/:cat/:id' => redirect('/products/%{id}')

This redirect work, but if the param id contain some character I get the error like this example:

Started GET "/merchandises/perfumes/Drakkar%20Noir%20Eau%20De%20Toilette" for 127.0.0.1 at 2012-03-07 23:21:28 +0100

URI::InvalidURIError (bad URI(is not URI?): /products/Drakkar Noir Eau De Toilette)

Someone can tell me how to fix this?

Pioz
  • 6,051
  • 4
  • 48
  • 67

1 Answers1

7

Ok, I've found a solution:

get '/merchandises/:cat/:id' => redirect { |params, req| "/products/#{URI.escape(params[:id])}" }
Pioz
  • 6,051
  • 4
  • 48
  • 67