ActionController::Routings:Routes#build_query_string doesn't support boolean params properly #4307

georgeqchen opened this Issue Jan 4, 2012 · 3 comments


None yet

3 participants


This is the current implementation from apidock,

File actionpack/lib/action_controller/routing/route.rb, line 48

  def build_query_string(hash, only_keys = nil)
    elements = []

    (only_keys || hash.keys).each do |key|
      if value = hash[key]            
        elements << value.to_query(key)

    elements.empty? ? '' : "?#{elements.sort * '&'}"

The issue here is that if you create a url with an optional url param that is a boolean and has value = false, then the above code will neglect the url param.

For in stance, if you call:
url_for(:controller => 'users',
:action => 'new',
:host => '',
The expected url should be: ""
The actual url generated is: ""

The error is on the line: if value = hash[key]
Instead, it should be: unless (value = hash[key]).nil?


This issue is about Rails 2.3.x ?


Yes, I am running 2.3.2. From the apidock, looks like the latest version of this file is on 2.3.8, which still has the issue.


Please upgrade to Rails 3.0.x and try again. Rails 2.3.x will only be released and patch in the event of security issues. Thanks!

@tenderlove tenderlove closed this Jan 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment