简体   繁体   English

Rails从网址中删除某些参数

[英]Rails remove certain params from url

What's the best method for removing certain params from a url? 从网址中删除某些参数的最佳方法是什么? For example I'm looking to change: 例如,我要更改:

www.testsite.com/blog?blog_id=1582 www.testsite.com/blog?blog_id=1582

to

www.testsite.com/blog/1582 www.testsite.com/blog/1582

<%= link_to list.blog_name, blog_blogs_path(blog_id: list.blog_id) %>
  1. I would double check your path as typically when linking to a direct item it is singular and not plural. 当链接到直接项目时,我会仔细检查您的路径,因为它是单数而不是复数。
  2. You just need the ID to be passed into the path 您只需要将ID传递到路径中

Example: 例:

<%= link_to list.blog_name, blog_blog_path(list.blog_id) %>

Note the path is now: blog_blog_path (no s) 请注意,路径现在是:blog_blog_path(否)

使链接成为变量,然后进行字符串替换

myString.gsub("?blod_id=", "/")
<%= link_to "blogs/index/#{list.blog_id}" %>

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

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