Skip to content

Commit 2f012f7

Browse files
authored
Merge pull request rails#42020 from chaymaeBZ/merge-params-when-it-is-a-hash
Only merge params option if params is a Hash in url_for helper
2 parents 52bed18 + b973e00 commit 2f012f7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,10 @@ def url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil
822822
path = route_with_params.path(method_name)
823823
params = route_with_params.params
824824

825-
if options.key? :params
825+
if options[:params].is_a?(Hash)
826826
params.merge! options[:params]
827+
elsif options.key? :params
828+
params[:params] = options[:params]
827829
end
828830

829831
options[:path] = path

actionpack/test/controller/url_for_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ def test_params_option
362362
assert_equal({ id: "1" }.to_query, params[1])
363363
end
364364

365+
def test_non_hash_params_option
366+
url = W.new.url_for(only_path: true, controller: "c", action: "a", params: "p")
367+
params = extract_params(url)
368+
assert_equal("/c/a?params=p", url)
369+
assert_equal({ params: "p" }.to_query, params[0])
370+
end
371+
365372
def test_hash_parameter
366373
url = W.new.url_for(only_path: true, controller: "c", action: "a", query: { name: "Bob", category: "prof" })
367374
params = extract_params(url)

0 commit comments

Comments
 (0)