Permalink
Browse files

Remove leading slash from controller [#5651 state:resolved]

  • Loading branch information...
1 parent 7d54fba commit 301462c89b2f21f399ff538d821d09258836dafa @pixeltrix pixeltrix committed Sep 18, 2010
Showing with 9 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +8 −0 actionpack/test/dispatch/routing_test.rb
@@ -128,7 +128,7 @@ def default_controller_and_action(to_shorthand=nil)
{ }
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
@@ -457,6 +457,8 @@ def self.matches?(request)
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 @@ def test_nested_resource_constraints
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

0 comments on commit 301462c

Please sign in to comment.