Skip to content

Commit e492c44

Browse files
tumayuncarlosantoniodasilva
authored andcommitted
Fix issue with params in url_for
With a "params" argument, the following error is raised: undefined method `reject!` for "":String
1 parent bba8fc4 commit e492c44

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

actionpack/lib/action_dispatch/http/url.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def url_for(options = {})
2828
path = options.delete(:script_name).to_s.chomp("/")
2929
path << options.delete(:path).to_s
3030

31-
params = options[:params] || {}
31+
params = options[:params].is_a?(Hash) ? options[:params] : {}
3232
params.reject! { |_,v| v.to_param.nil? }
3333

3434
result = build_host_url(options)

actionpack/test/dispatch/request_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,14 @@ def url_for(options = {})
799799
end
800800
end
801801

802+
test "url_for options[:params]" do
803+
assert_equal 'http://www.example.com?params=', url_for(:params => '')
804+
assert_equal 'http://www.example.com?params=1', url_for(:params => 1)
805+
assert_equal 'http://www.example.com', url_for
806+
assert_equal 'http://www.example.com', url_for(:params => {})
807+
assert_equal 'http://www.example.com?name=tumayun', url_for(:params => { :name => 'tumayun' })
808+
end
809+
802810
protected
803811

804812
def stub_request(env = {})

0 commit comments

Comments
 (0)