问题
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)
回答1:
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.
来源:https://stackoverflow.com/questions/10815349/ruby-on-rails-passing-params-into-301-redirect-in-routes-rb