Url_for: /action?key

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

/my_controller/my_action?flag

and not

/my_controller/my_action?flag=1

or

/my_controller/my_action?flag=

Is that possible with the Rails helpers?

Gareth

The short answer is no.

Query string generation is deep down in the routing code…

http://dev.rubyonrails.org/browser/trunk/actionpack/lib/
action_controller/routing.rb#L443

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” : “”)
url
end

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.

-christos