Last Updated: February 25, 2016
· 2called-chaos

Be careful with params.merge()

I've seen a lot of people doing it and I used to do it too, use params.merge(…) in link_to or redirect_to calls. You do this because you want to change one ore more parameters (like the locale, current page or search query) but leave the rest as it is.

But heads up! There is an issue with this solution:

link_to("Page 2", params.merge(page: 2)) # /users?page=2
link_to("parlez vous français?", params.merge(locale: "fr")) # /fr/about

What do you think would this request url do to the second link? Hint: You won't get a french customer anymore :)




which results in you link target being

There is also protocol you could tamper with. So if you have french customers you might want to know how to get out of this misery.

=> Read full article + possible solutions on our blog