aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-11-25 22:24:23 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-11-25 22:24:23 +0000
commit9e76b59c85d94148e20999a2943777cb1fe0bee9 (patch)
tree4ac3d9a00bbb186e860057c722b4953ae631fb23
parentf4b5ca1ff0113e41c974b7cbda1f734f9c0526fe (diff)
downloadrails-9e76b59c85d94148e20999a2943777cb1fe0bee9.tar.gz
rails-9e76b59c85d94148e20999a2943777cb1fe0bee9.tar.bz2
rails-9e76b59c85d94148e20999a2943777cb1fe0bee9.zip
Fixed that named routes living under resources shouldn't have double slashes (closes #10198) [isaacfeliu]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8206 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb2
-rw-r--r--actionpack/test/controller/routing_test.rb14
3 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index e197e334aa..ec19b42a5e 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that named routes living under resources shouldn't have double slashes #10198 [isaacfeliu]
+
* Make sure that cookie sessions use a secret that is at least 30 chars in length. [Koz]
* Fixed that partial rendering should look at the type of the first render to determine its own type if no other clues are available (like when using text.plain.erb as the extension in AM) #10130 [java]
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 2e8951e36d..1b7eb74db1 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -1012,7 +1012,7 @@ module ActionController
path = "/#{path}" unless path[0] == ?/
path = "#{path}/" unless path[-1] == ?/
- path = "/#{options[:path_prefix]}#{path}" if options[:path_prefix]
+ path = "/#{options[:path_prefix].gsub(/^\//,'')}#{path}" if options[:path_prefix]
segments = segments_for_route_path(path)
defaults, requirements, conditions = divide_route_options(segments, options)
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 5198efd8e6..1036d7f3bf 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -1980,6 +1980,20 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal '/post/show/10', all.last
end
+ def test_named_route_in_nested_resource
+ set.draw do |map|
+ map.resources :projects do |project|
+ project.comments 'comments', :controller => 'comments', :action => 'index'
+ end
+ end
+
+ request.path = "/projects/1/comments"
+ request.method = :get
+ assert_nothing_raised { set.recognize(request) }
+ assert_equal("comments", request.path_parameters[:controller])
+ assert_equal("index", request.path_parameters[:action])
+ end
+
end
class RoutingTest < Test::Unit::TestCase