aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb2
-rw-r--r--actionpack/test/dispatch/routing_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 8a161b0837..42ca351cfa 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -137,7 +137,7 @@ module ActionDispatch
{ }
else
if to.is_a?(String)
- controller, action = to.split('#')
+ controller, action = to.sub(%r{\A/}, '').split('#')
elsif to.is_a?(Symbol)
action = to.to_s
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 8a2311ab3e..b5a4674a16 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -457,6 +457,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match '/cities', :to => 'countries#cities'
end
+ match '/feeds/:service', :to => '/api/feeds#show', :as => :feed
+
match '/countries/:country/(*other)', :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : '/countries/all' }
match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/
@@ -2128,6 +2130,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_raises(ActionController::RoutingError){ list_todo_path(:list_id => '2', :id => '1') }
end
+ def test_controller_has_leading_slash_removed
+ get '/feeds/twitter.xml'
+ assert_equal 'api/feeds#show', @response.body
+ assert_equal '/feeds/twitter.xml', feed_path(:service => 'twitter', :format => 'xml')
+ end
+
private
def with_test_routes
yield