加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 如何在routes.rb中传递查询字符串上的重定向

发布时间:2020-12-16 19:26:07 所属栏目:百科 来源:网络整理
导读:我的路线有一个功能重定向. match "/invoices" = redirect("/dashboard") 我现在想添加一个查询字符串到这个,例如, /invoices?show=overdue 将被重定向到 /dashboard?show=overdue 我尝试过几件事情我最接近的是 match "/invoices?:string" = redirect("/das
我的路线有一个功能重定向.
match "/invoices" => redirect("/dashboard")

我现在想添加一个查询字符串到这个,例如,

/invoices?show=overdue

将被重定向到

/dashboard?show=overdue

我尝试过几件事情我最接近的是

match "/invoices?:string" => redirect("/dashboard?%{string}")

这给我正确的输出,但原始的URL仍然显示在浏览器中.

我相信我错过了很简单的东西,但是我看不到什么.

解决方法

在这种情况下可以使用request对象:
match "/invoices" => redirect{ |p,request| "/dashboard?#{request.query_string}" }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读