1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix issue with params in url_for

With a "params" argument, the following error is raised:

    undefined method `reject!` for "":String
This commit is contained in:
tumayun 2012-11-16 12:11:03 +08:00 committed by Carlos Antonio da Silva
parent bba8fc4294
commit e492c446d5
2 changed files with 9 additions and 1 deletions

View file

@ -28,7 +28,7 @@ module ActionDispatch
path = options.delete(:script_name).to_s.chomp("/")
path << options.delete(:path).to_s
params = options[:params] || {}
params = options[:params].is_a?(Hash) ? options[:params] : {}
params.reject! { |_,v| v.to_param.nil? }
result = build_host_url(options)

View file

@ -799,6 +799,14 @@ class RequestTest < ActiveSupport::TestCase
end
end
test "url_for options[:params]" do
assert_equal 'http://www.example.com?params=', url_for(:params => '')
assert_equal 'http://www.example.com?params=1', url_for(:params => 1)
assert_equal 'http://www.example.com', url_for
assert_equal 'http://www.example.com', url_for(:params => {})
assert_equal 'http://www.example.com?name=tumayun', url_for(:params => { :name => 'tumayun' })
end
protected
def stub_request(env = {})