Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to the current page plus/merged with a param [duplicate]

A bit of a softball question, but my Google Fu escapes me at the moment.

How do I link to the current page but then specify params to be merged into the query string?

For instance, if the current page is /resources, I want to be able to specify something like current_page_plus(:param => 'attribute') that evaluates out to /resources?param=attribute.

This would hopefully also merge with existing attributes, so if the current page was /resources?a=b&c=d, then current_page_plus(:c => 'e') would evaluate to /resources?a=b&c=e.

like image 457
Steven Avatar asked Apr 04 '11 07:04

Steven


1 Answers

You can use url_for passing the params.

url_for(params.merge(:c => "e"))

If you use an helper like link_to that internally uses url_for you can skip the url_for and pass the has directly.

link_to "Page", params.merge(:c => "e")
like image 147
Simone Carletti Avatar answered Nov 20 '22 08:11

Simone Carletti