提交 3a48b83e 编写于 作者: A Andrew White

Allow an absolute controller path inside a module scope

Fixes #12777
上级 a1564d47
* Allow an absolute controller path inside a module scope
Fixes #12777
* Unique the segment keys array for non-optimized url helpers * Unique the segment keys array for non-optimized url helpers
In Rails 3.2 you only needed pass an argument for dynamic segment once so In Rails 3.2 you only needed pass an argument for dynamic segment once so
......
...@@ -218,8 +218,12 @@ def default_controller_and_action ...@@ -218,8 +218,12 @@ def default_controller_and_action
controller ||= default_controller controller ||= default_controller
action ||= default_action action ||= default_action
unless controller.is_a?(Regexp) if @scope[:module] && !controller.is_a?(Regexp)
controller = [@scope[:module], controller].compact.join("/").presence if controller =~ %r{\A/}
controller = controller[1..-1]
else
controller = [@scope[:module], controller].compact.join("/").presence
end
end end
if controller.is_a?(String) && controller =~ %r{\A/} if controller.is_a?(String) && controller =~ %r{\A/}
......
...@@ -2882,6 +2882,18 @@ def test_multiple_positional_args_with_the_same_name ...@@ -2882,6 +2882,18 @@ def test_multiple_positional_args_with_the_same_name
assert_equal '/downloads/1/1.tar', download_path('1', '1') assert_equal '/downloads/1/1.tar', download_path('1', '1')
end end
def test_absolute_controller_namespace
draw do
namespace :foo do
get '/', to: '/bar#index', as: 'root'
end
end
get '/foo'
assert_equal 'bar#index', @response.body
assert_equal '/foo', foo_root_path
end
private private
def draw(&block) def draw(&block)
......
...@@ -239,6 +239,8 @@ In each of these cases, the named routes remain the same as if you did not use ` ...@@ -239,6 +239,8 @@ In each of these cases, the named routes remain the same as if you did not use `
| PATCH/PUT | /admin/posts/:id | posts#update | post_path(:id) | | PATCH/PUT | /admin/posts/:id | posts#update | post_path(:id) |
| DELETE | /admin/posts/:id | posts#destroy | post_path(:id) | | DELETE | /admin/posts/:id | posts#destroy | post_path(:id) |
TIP: _If you need to use a different controller namespace inside a `namespace` block you can specify an absolute controller path, e.g: `get '/foo' => '/foo#index'`._
### Nested Resources ### Nested Resources
It's common to have resources that are logically children of other resources. For example, suppose your application includes these models: It's common to have resources that are logically children of other resources. For example, suppose your application includes these models:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册