提交 c02b8561 编写于 作者: K Kasper Timm Hansen

Merge pull request #20109 from prathamesh-sonpatki/keep-only-one-root

 Remove original root method from Base module and kept overridden implementation in Resources module.
......@@ -387,24 +387,6 @@ def self.normalize_name(name)
end
module Base
# You can specify what Rails should route "/" to with the root method:
#
# root to: 'pages#main'
#
# For options, see +match+, as +root+ uses it internally.
#
# You can also pass a string which will expand
#
# root 'pages#main'
#
# You should put the root route at the top of <tt>config/routes.rb</tt>,
# because this means it will be matched first. As this is the most popular route
# of most Rails applications, this is beneficial.
def root(options = {})
name = has_named_route?(:root) ? nil : :root
match '/', { as: name, via: :get }.merge!(options)
end
# Matches a url pattern to one or more routes.
#
# You should not use the +match+ method in your router
......@@ -1689,7 +1671,20 @@ def add_route(action, controller, options, _path, to, via, formatted, anchor, op
@set.add_route(mapping, ast, as, anchor)
end
def root(path, options={})
# You can specify what Rails should route "/" to with the root method:
#
# root to: 'pages#main'
#
# For options, see +match+, as +root+ uses it internally.
#
# You can also pass a string which will expand
#
# root 'pages#main'
#
# You should put the root route at the top of <tt>config/routes.rb</tt>,
# because this means it will be matched first. As this is the most popular route
# of most Rails applications, this is beneficial.
def root(path, options = {})
if path.is_a?(String)
options[:to] = path
elsif path.is_a?(Hash) and options.empty?
......@@ -1701,11 +1696,11 @@ def root(path, options={})
if @scope.resources?
with_scope_level(:root) do
path_scope(parent_resource.path) do
super(options)
match_root_route(options)
end
end
else
super(options)
match_root_route(options)
end
end
......@@ -1900,6 +1895,11 @@ def path_scope(path)
ensure
@scope = @scope.parent
end
def match_root_route(options)
name = has_named_route?(:root) ? nil : :root
match '/', { :as => name, :via => :get }.merge!(options)
end
end
# Routing Concerns allow you to declare common routes that can be reused
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册