提交 8a8dac80 编写于 作者: R rono23

Fix name_for_action in routing

上级 19b4b0df
......@@ -1739,9 +1739,10 @@ def name_for_action(as, action) #:nodoc:
member_name = parent_resource.member_name
end
name = @scope.action_name(name_prefix, prefix, collection_name, member_name)
action_name = @scope.action_name(name_prefix, prefix, collection_name, member_name)
candidate = action_name.select(&:present?).join('_')
if candidate = name.compact.join("_").presence
unless candidate.empty?
# If a name was not explicitly given, we check if it is valid
# and return nil in case it isn't. Otherwise, we pass the invalid name
# forward so the underlying router engine treats it and raises an exception.
......
......@@ -3439,6 +3439,44 @@ def test_scope_shallow_path_is_not_overwritten_by_path
assert_equal '/bar/comments/1', comment_path('1')
end
def test_resource_where_as_is_empty
draw do
resource :post, as: ''
scope 'post', as: 'post' do
resource :comment, as: ''
end
end
assert_equal '/post/new', new_path
assert_equal '/post/comment/new', new_post_path
end
def test_resources_where_as_is_empty
draw do
resources :posts, as: ''
scope 'posts', as: 'posts' do
resources :comments, as: ''
end
end
assert_equal '/posts/new', new_path
assert_equal '/posts/comments/new', new_posts_path
end
def test_scope_where_as_is_empty
draw do
scope 'post', as: '' do
resource :user
resources :comments
end
end
assert_equal '/post/user/new', new_user_path
assert_equal '/post/comments/new', new_comment_path
end
private
def draw(&block)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册