Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - passing params into 301 redirect in routes.rb

I want to change my existing 'game' routing inside routes.rb, but because of SEO I need also to setup 301 redirect for old links.

My old routing:

match 'games/:permalink/:id/(:page)' => 'games#show'

New routing:

match 'gierki/:permalink/(:page)' => 'games#show'

Here is redirection which I tried to to do:

match 'games/:permalink/:id/(:page)' => redirect {|params| "/gierki/#{params[:permalink]}" + params[:page].nil? ? "" : "/#{params[:page]}" }

Above redirect is not working, here is an error:

wrong number of arguments (1 for 2)
like image 679
Arti Avatar asked May 30 '12 11:05

Arti


1 Answers

Try making it like this:

match 'games/:permalink/:id/(:page)' => redirect {|params,request| "/gierki/#{params[:permalink]}" + params[:page].nil? ? "" : "/#{params[:page]}" }

And see if it works.

like image 73
Maurício Linhares Avatar answered Oct 06 '22 14:10

Maurício Linhares