Pioz
Pioz

Reputation: 6321

URI::InvalidURIError on rails routing redirect

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?

Upvotes: 4

Views: 868

Answers (1)

Pioz
Pioz

Reputation: 6321

Ok, I've found a solution:

get '/merchandises/:cat/:id' => redirect { |params, req| "/products/#{URI.escape(params[:id])}" }

Upvotes: 7

Related Questions