diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 3e15caee2d..9c30f2a27a 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -124,11 +124,13 @@ module ActionDispatch controller, action = to.split('#') { :controller => controller, :action => action } when Symbol - { :action => to.to_s }.merge(default_controller ? { :controller => default_controller } : {}) + { :action => to.to_s } else - default_controller ? { :controller => default_controller } : {} + {} end + defaults[:controller] ||= @options[:controller] || default_controller + if defaults[:controller].blank? && segment_keys.exclude?("controller") raise ArgumentError, "missing :controller" end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 411a28d8ee..d32d708b35 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -52,6 +52,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'global/:action' end + match "/local/:action", :controller => "local" + constraints(:ip => /192\.168\.1\.\d\d\d/) do get 'admin' => "queenbee#index" end @@ -415,6 +417,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_local + with_test_routes do + get '/local/dashboard' + assert_equal 'local#dashboard', @response.body + end + end + def test_projects with_test_routes do get '/projects'