DollarChills
DollarChills

Reputation: 1086

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

to

www.testsite.com/blog/1582

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

Upvotes: 0

Views: 509

Answers (3)

Hemanth M C
Hemanth M C

Reputation: 436

<%= link_to "blogs/index/#{list.blog_id}" %>

Upvotes: 0

Michael Moulsdale
Michael Moulsdale

Reputation: 1488

make the link a variable and then carry out a string substitution

myString.gsub("?blod_id=", "/")

Upvotes: 0

Adam21e
Adam21e

Reputation: 791

  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

Example:

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

Note the path is now: blog_blog_path (no s)

Upvotes: 1

Related Questions