mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix url_for method's behavior when it is called with :controller option which starts with "/" from multiple nested controller.
Closes #3864
This commit is contained in:
parent
af7dafff81
commit
837231a829
2 changed files with 34 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue