url_for: /action?key

Hi guys,
I want to write a url that directs to


and not




Is that possible with the Rails helpers?


The short answer is no.

Query string generation is deep down in the routing code...


Having said that, if you want, you can put in your
ApplicationControler in application.rb the following method...

   def url_for ( options = {}, *params)
     flag = options.key?(:flag) ? options.delete(:flag) : false
     url = super(options, *params)
     url << (flag ? "?flag" : "")

That overloads (...or monkeypatches, whatever!) the url_for
generation code for your application.

That is, provided that all parts of your app use @controller.send
(:url_for, options, *params) to generate their URLs, or use the Rails
helpers who should do that uniformly.