Permalink
Browse files

Merge pull request #4908 from kennyj/fix_3864

Fix url_for method's behavior. GH #3684.
  • Loading branch information...
1 parent 93f5361 commit ab44418881c80b757ebd50fb026cae91894fbe6a @josevalim josevalim committed with josevalim Feb 6, 2012
Showing with 34 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  2. +33 −0 actionpack/test/dispatch/routing_test.rb
View
2 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -489,7 +489,7 @@ def normalize_controller_action_id!
# 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
View
33 actionpack/test/dispatch/routing_test.rb
@@ -2562,3 +2562,36 @@ def app; Routes end
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
+

0 comments on commit ab44418

Please sign in to comment.