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

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:01:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!