Permalink
Browse files

Fix issue with params in url_for

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

    undefined method `reject!` for "":String
  • Loading branch information...
1 parent bba8fc4 commit e492c446d520e8941624564b157b297cfd0aeaa9 @tumayun tumayun committed with carlosantoniodasilva Nov 16, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/http/url.rb
  2. +8 −0 actionpack/test/dispatch/request_test.rb
View
2 actionpack/lib/action_dispatch/http/url.rb
@@ -28,7 +28,7 @@ def url_for(options = {})
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
8 actionpack/test/dispatch/request_test.rb
@@ -799,6 +799,14 @@ def url_for(options = {})
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 = {})

0 comments on commit e492c44

Please sign in to comment.