简体   繁体   English

Rails-使用参数重定向URL(路由)

[英]Rails - Redirect URL with params (routes)

I'm trying to create a redirect for anyone that has parameters in a certain url, to the homepage. 我正在尝试为在某个url中具有参数的任何人创建到首页的重定向。 I currently have this in my routes: 我目前在航线上有这个:

match "/pr?campaign=#{'params[:campaign]'}" => redirect("/")

but it's not recognising it properly, if i put /pr?campaign=test into the url I get a page not found.. 但它不能正确识别它,如果我将/pr?campaign=test放入url中,则找不到页面。

I'm not sure if I'm understanding your question, maybe try this: 我不确定是否能理解您的问题,请尝试以下操作:

match '/pr'           => 'controller#action'           # responds to no additional params
match '/pr/:campaign' => 'another_controller#action'   # responds to another param.

So, /pr will be received by controller#action , but /pr/test will be received by another_controller#action and receive test as params[:campaign] 因此, /pr将由controller#action接收,但/pr/test将由another_controller#action接收并以params[:campaign]接收测试

Edit (actual solution to this problem): 编辑(此问题的实际解决方案):

match '/pr' => redirect('/')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM