Ruby on Rails: pass query parameters hash with key but nil value

450 Views Asked by At

In Ruby on Rails, my current url has a query parameter of ?hello. Since the request.query_parameters hash will be {:hello=>nil}, how do I pass this with link_to? Rails seems to drop any query parameter that has a nil value.

1

There are 1 best solutions below

0
Starscream512 On BEST ANSWER

I don't think there's really an elegant way. The best hack seems to be something like this:

_hello = '?hello' if request.query_parameters.fetch(:hello, false).nil?
link_to('click here', some_path+"#{_hello}")