diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-07 12:03:22 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-07 12:03:22 +0100 |
commit | c02b85614c6c497ea1fd4c33415335621b090f29 (patch) | |
tree | 80f22c40ddd79920cafadf75bf34f48274e9de62 | |
parent | 45da423bf35d1827f35ead2af40a7d22bcf58686 (diff) | |
parent | ee1534e5ab51fccb0fe3dbc06fba7ffbe44d070f (diff) | |
download | rails-c02b85614c6c497ea1fd4c33415335621b090f29.tar.gz rails-c02b85614c6c497ea1fd4c33415335621b090f29.tar.bz2 rails-c02b85614c6c497ea1fd4c33415335621b090f29.zip |
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.
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 18cd205bad..522012063d 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -387,24 +387,6 @@ module ActionDispatch 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 @@ to this: @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 @@ to this: 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 @@ to this: 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 |