Fix a bug in url generation for generic routes.
This commit is contained in:
parent
25cb21328a
commit
86defed5ad
|
@ -129,7 +129,10 @@ module ActionDispatch
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
defaults[:controller] ||= @options[:controller] || default_controller
|
defaults[:controller] ||= default_controller
|
||||||
|
|
||||||
|
defaults.delete(:controller) if defaults[:controller].blank?
|
||||||
|
defaults.delete(:action) if defaults[:action].blank?
|
||||||
|
|
||||||
if defaults[:controller].blank? && segment_keys.exclude?("controller")
|
if defaults[:controller].blank? && segment_keys.exclude?("controller")
|
||||||
raise ArgumentError, "missing :controller"
|
raise ArgumentError, "missing :controller"
|
||||||
|
@ -177,7 +180,11 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_controller
|
def default_controller
|
||||||
@scope[:controller].to_s if @scope[:controller]
|
if @options[:controller]
|
||||||
|
@options[:controller].to_s
|
||||||
|
elsif @scope[:controller]
|
||||||
|
@scope[:controller].to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||||
resource :me
|
resource :me
|
||||||
match '/' => 'mes#index'
|
match '/' => 'mes#index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match "whatever/:controller(/:action(/:id))"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -979,6 +981,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_url_generator_for_generic_route
|
||||||
|
with_test_routes do
|
||||||
|
get 'whatever/foo/bar'
|
||||||
|
assert_equal 'foo#bar', @response.body
|
||||||
|
|
||||||
|
assert_equal 'http://www.example.com/whatever/foo/bar/1',
|
||||||
|
url_for(:controller => "foo", :action => "bar", :id => 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def with_test_routes
|
def with_test_routes
|
||||||
yield
|
yield
|
||||||
|
|
Loading…
Reference in New Issue