How to add parameters to current URL in rails

Viewed 51254

I have a logic where I allow sorting on price and relevance. I am doing this by passing parameters to controller. My URL has a parameter - 'sort' which can have a value - 'price_lowest' or 'default'. The links looks like:

<a href="<%= request.fullpath + '&sort=price_lowest' %>">lowest prices</a> | 
<a href="<%= request.fullpath + '&sort=default' %>">relevance</a>

problem with the above code is that it "adds" parameters and does not "replace" them. I want to replace the value of &sort= parameter without adding a new value. E.g. I don't want :

../&sort=price_lowest&sort=price_lowest&sort=default

With the current logic - I am getting the above behaviour. Any suggestions ?

5 Answers
Related