我如何在传递查询字符串的route.rb中进行重定向 [英] How do I do a redirection in routes.rb passing on the query string
本文介绍了我如何在传递查询字符串的route.rb中进行重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的route.rb中的重定向功能正常;
I had a functioning redirect in my routes.rb like so;
match "/invoices" => redirect("/dashboard")
我现在想向其添加查询字符串,例如,
I now want to add a query string to this so that, e.g.,
/invoices?show=overdue
将重定向到
/dashboard?show=overdue
我尝试了几件事。我最接近的是;
I've tried several things. The closest I have got is;
match "/invoices?:string" => redirect("/dashboard?%{string}")
这为我提供了正确的输出,但带有原始URL仍显示在浏览器中。
which gives me the correct output but with the original URL still displayed in the browser.
我确定我遗漏了一些非常简单的内容,但看不到什么。
I'm sure I'm missing something pretty simple, but I can't see what.
推荐答案
在这种情况下,您可以使用请求对象:
You can use request object in this case:
match "/invoices" => redirect{ |p, request| "/dashboard?#{request.query_string}" }
这篇关于我如何在传递查询字符串的route.rb中进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文