rails/rails — Issue #4307: ActionController::Routings:Routes#build_query_string doesn't support boolean params properly
Author: georgeqchen
Created: 2012-01-04 22:36:35+00:00
State: open

This is the current implementation from apidock,

http://apidock.com/rails/v2.3.8/ActionController/Routing/Route/build_query_string

# 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)
end
end

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

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 => 'www.example.com',
:activated=>false)
The expected url should be: "http://www.example.com/users/new?activated=false"
The actual url generated is: "http://www.example.com/users/new"

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