是否可以在routes.rb中创建快速重定向规则以支持:
自:
http://example.com/family/uid-123-child
要:
http://example.com/family/parent?child=123
我目前的解决方案如下。 Rails不允许我解析:id来获取数字“123”。你能帮忙吗?
get "family/:id", to: redirect('/parent?child='.concat('%{id}')), :constraints => { :id => /[A-Za-z0-9_\-:]+\child?/}
答案 0 :(得分:0)
您可以将块传递给redirect
,这允许您修改重定向的参数:
get "family/:id", to: redirect { |params, request| "/family/parent?child=#{params[:id][/[0-9]+/]}" }, constraints: { id: /[A-Za-z0-9_\-:]+child?/ }