aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-02-06 01:07:49 +0900
committerkennyj <kennyj@gmail.com>2012-02-07 00:45:01 +0900
commit837231a8295be63aa3dcbf867b457b2a7aa27386 (patch)
treefe40cf4620ce154ba282a58671e3ae175855bb30
parentaf7dafff818094a6e02505fe7d6d87add6c2a7e8 (diff)
downloadrails-837231a8295be63aa3dcbf867b457b2a7aa27386.tar.gz
rails-837231a8295be63aa3dcbf867b457b2a7aa27386.tar.bz2
rails-837231a8295be63aa3dcbf867b457b2a7aa27386.zip
Fix url_for method's behavior when it is called with :controller option which starts with "/" from multiple nested controller.
Closes #3864
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb2
-rw-r--r--actionpack/test/dispatch/routing_test.rb33
2 files changed, 34 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index ac4dd7d927..c96999d23f 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -482,7 +482,7 @@ module ActionDispatch
# if the current controller is "foo/bar/baz" and :controller => "baz/bat"
# is specified, the controller becomes "foo/baz/bat"
def use_relative_controller!
- if !named_route && different_controller?
+ if !named_route && different_controller? && !controller.start_with?("/")
old_parts = current_controller.split('/')
size = controller.count("/") + 1
parts = old_parts[0...-size] << controller
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index b9c0189303..1216193075 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2562,3 +2562,36 @@ class TestUnicodePaths < ActionDispatch::IntegrationTest
assert_equal "200", @response.code
end
end
+
+class TestMultipleNestedController < ActionDispatch::IntegrationTest
+ module ::Foo
+ module Bar
+ class BazController < ActionController::Base
+ def index
+ render :inline => "<%= url_for :controller => '/pooh', :action => 'index' %>"
+ end
+ end
+ end
+ end
+
+ Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
+ app.draw do
+ namespace :foo do
+ namespace :bar do
+ match "baz" => "baz#index"
+ end
+ end
+ match "pooh" => "pooh#index"
+ end
+ end
+
+ include Routes.url_helpers
+ def app; Routes end
+
+ test "controller option which starts with '/' from multiple nested controller" do
+ get "/foo/bar/baz"
+ assert_equal "/pooh", @response.body
+ end
+
+end
+