Skip to content
This repository
Browse code

Merge pull request #4908 from kennyj/fix_3864

Fix url_for method's behavior. GH #3684.
  • Loading branch information...
commit ab44418881c80b757ebd50fb026cae91894fbe6a 1 parent 93f5361
José Valim josevalim authored josevalim committed
2  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -489,7 +489,7 @@ def normalize_controller_action_id!
489 489 # if the current controller is "foo/bar/baz" and :controller => "baz/bat"
490 490 # is specified, the controller becomes "foo/baz/bat"
491 491 def use_relative_controller!
492   - if !named_route && different_controller?
  492 + if !named_route && different_controller? && !controller.start_with?("/")
493 493 old_parts = current_controller.split('/')
494 494 size = controller.count("/") + 1
495 495 parts = old_parts[0...-size] << controller
33 actionpack/test/dispatch/routing_test.rb
@@ -2562,3 +2562,36 @@ def app; Routes end
2562 2562 assert_equal "200", @response.code
2563 2563 end
2564 2564 end
  2565 +
  2566 +class TestMultipleNestedController < ActionDispatch::IntegrationTest
  2567 + module ::Foo
  2568 + module Bar
  2569 + class BazController < ActionController::Base
  2570 + def index
  2571 + render :inline => "<%= url_for :controller => '/pooh', :action => 'index' %>"
  2572 + end
  2573 + end
  2574 + end
  2575 + end
  2576 +
  2577 + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
  2578 + app.draw do
  2579 + namespace :foo do
  2580 + namespace :bar do
  2581 + match "baz" => "baz#index"
  2582 + end
  2583 + end
  2584 + match "pooh" => "pooh#index"
  2585 + end
  2586 + end
  2587 +
  2588 + include Routes.url_helpers
  2589 + def app; Routes end
  2590 +
  2591 + test "controller option which starts with '/' from multiple nested controller" do
  2592 + get "/foo/bar/baz"
  2593 + assert_equal "/pooh", @response.body
  2594 + end
  2595 +
  2596 +end
  2597 +

0 comments on commit ab44418

Please sign in to comment.
Something went wrong with that request. Please try again.