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

Revert "Don't handle params option in a special way in url_for helper"

This reverts commit e385e4678f.

While this option was undocumented it exists to make possible to pass
parameters to the route helpers that are reserved like `:domain`.

While `url_for(domain: 'foo.com')` would generate a URL in the `foo.com`
domain `url_for(params: { domain: 'foo.com' })` would generate a URL
with `?domain=foo.com`.
This commit is contained in:
Rafael Mendonça França 2019-01-16 10:58:58 -05:00
parent d67863af39
commit 17e4b49292
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
5 changed files with 14 additions and 5 deletions

View file

@ -85,10 +85,6 @@
*Yoshiyuki Kinjo*
* Remove undocumented `params` option from `url_for` helper.
*Ilkka Oksanen*
* Encode Content-Disposition filenames on `send_data` and `send_file`.
Previously, `send_data 'data', filename: "\u{3042}.txt"` sends
`"filename=\"\u{3042}.txt\""` as Content-Disposition and it can be

View file

@ -820,6 +820,10 @@ module ActionDispatch
path, params = generate(route_name, path_options, recall)
if options.key? :params
params.merge! options[:params]
end
options[:path] = path
options[:script_name] = script_name
options[:params] = params

View file

@ -133,6 +133,7 @@ module ActionDispatch
# <tt>ActionDispatch::Http::URL.tld_length</tt>, which in turn defaults to 1.
# * <tt>:port</tt> - Optionally specify the port to connect to.
# * <tt>:anchor</tt> - An anchor name to be appended to the path.
# * <tt>:params</tt> - The query parameters to be appended to the path.
# * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2009/"
# * <tt>:script_name</tt> - Specifies application path relative to domain root. If provided, prepends application path.
#

View file

@ -193,7 +193,7 @@ class UrlOptionsTest < ActionController::TestCase
action: "home",
controller: "pages",
only_path: true,
token: "secret"
params: { "token" => "secret" }
}
assert_equal "/home?token=secret", rs.url_for(options)

View file

@ -354,6 +354,14 @@ module AbstractController
assert_equal({ p2: "Y2" }.to_query, params[1])
end
def test_params_option
url = W.new.url_for(only_path: true, controller: "c", action: "a", params: { domain: "foo", id: "1" })
params = extract_params(url)
assert_equal("/c/a?domain=foo&id=1", url)
assert_equal({ domain: "foo" }.to_query, params[0])
assert_equal({ id: "1" }.to_query, params[1])
end
def test_hash_parameter
url = W.new.url_for(only_path: true, controller: "c", action: "a", query: { name: "Bob", category: "prof" })
params = extract_params(url)