aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing_optimisation.rb11
-rw-r--r--actionpack/test/controller/routing_test.rb11
3 files changed, 17 insertions, 7 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 0a727f4016..6b2f30f1b1 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* root_path returns '/' not ''. #9563 [lifofifo]
+
* Fixed that setting request.format should also affect respond_to blocks [DHH]
* Add option to force binary mode on tempfile used for fixture_file_upload. #6380 [Jonathan Viney]
diff --git a/actionpack/lib/action_controller/routing_optimisation.rb b/actionpack/lib/action_controller/routing_optimisation.rb
index 535f1bed63..1b447b17e7 100644
--- a/actionpack/lib/action_controller/routing_optimisation.rb
+++ b/actionpack/lib/action_controller/routing_optimisation.rb
@@ -62,11 +62,10 @@ module ActionController
elements << '#{request.host_with_port}'
end
- # The last entry in route.segments appears to
- # *always* be a 'divider segment' for '/'
- # but we have assertions to ensure that we don't
- # include the trailing slashes, so skip them
- route.segments[0..-2].each do |segment|
+ # The last entry in route.segments appears to # *always* be a
+ # 'divider segment' for '/' but we have assertions to ensure that
+ # we don't include the trailing slashes, so skip them.
+ ((route.segments.size == 1 && kind == :path) ? route.segments : route.segments[0..-2]).each do |segment|
if segment.is_a?(DynamicSegment)
elements << "\#{URI.escape(args[#{idx}].to_param, ActionController::Routing::Segment::UNSAFE_PCHAR)}"
idx += 1
@@ -96,4 +95,4 @@ module ActionController
OPTIMISERS = [PositionalArguments, PositionalArgumentsWithAdditionalParams]
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 4901c93a60..fee1ad3ccf 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -218,7 +218,16 @@ class LegacyRouteSetTests < Test::Unit::TestCase
map.normal ':controller/:action/:id'
end
end
-
+
+ def test_named_route_root
+ rs.draw do |map|
+ map.root :controller => "hello"
+ end
+ x = setup_for_named_route
+ assert_equal("http://named.route.test", x.send(:root_url))
+ assert_equal("/", x.send(:root_path))
+ end
+
def test_named_route_with_regexps
rs.draw do |map|
map.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show',