提交 ce06d57e 编写于 作者: A Andrew White

Merge pull request #9599 from ognevsky/hash-inside-array-in-url-for

Take Hash with options inside Array in #url_for
* Take a hash with options inside array in #url_for
Example:
url_for [:new, :admin, :post, { param: 'value' }]
# => http://example.com/admin/posts/new?params=value
*Andrey Ognevsky*
* Add `session#fetch` method
fetch behaves similarly to [Hash#fetch](http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch),
......
......@@ -155,6 +155,8 @@ def url_for(options = nil)
_routes.url_for(options.symbolize_keys.reverse_merge!(url_options))
when String
options
when Array
polymorphic_url(options, options.extract_options!)
else
polymorphic_url(options)
end
......
......@@ -370,6 +370,24 @@ def test_false_url_params_are_included_in_query
assert_equal("/c/a?show=false", W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :show => false))
end
def test_url_generation_with_array_and_hash
with_routing do |set|
set.draw do
namespace :admin do
resources :posts
end
end
kls = Class.new { include set.url_helpers }
kls.default_url_options[:host] = 'www.basecamphq.com'
controller = kls.new
assert_equal("http://www.basecamphq.com/admin/posts/new?param=value",
controller.send(:url_for, [:new, :admin, :post, { param: 'value' }])
)
end
end
private
def extract_params(url)
url.split('?', 2).last.split('&').sort
......
......@@ -83,6 +83,8 @@ def url_for(options = nil)
super
when :back
_back_url
when Array
polymorphic_path(options, options.extract_options!)
else
polymorphic_path(options)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册