raulchopi
raulchopi

Reputation: 338

Add param to an existing URL in Rails 4 link_to

In my rails project I am in this URL, result of a search form:

http://localhost:3000/buscar?localidad=&page=2&&query=de

And I have an (a..z) list to order alphabetically the results. When I press the 'A' button I want to add a parameter to my previous URL, so it'd be like this:

http://localhost:3000/buscar?localidad=&page=2&&query=de&start=A

But in my 'A' button y have this link_to:

= link_to 'A', search_index_path(start: 'A')

so the URL is just:

http://localhost:3000/buscar?start=A

, removing all the previous params I had... :(

How can I do to 'concatenate' the params to the previous params I already had in the URL?

Thanks!

Upvotes: 0

Views: 947

Answers (1)

BroiSatse
BroiSatse

Reputation: 44725

You can do:

= link_to 'A', params.merge(start: 'A')

Upvotes: 2

Related Questions