Skip to content

Commit 2d0bb93

Browse files
committed
Improve deprecation for hash key mapping in routing
Related with rails#52422.
1 parent 2e0e65c commit 2d0bb93

File tree

1 file changed

+20
-9
lines changed
  • actionpack/lib/action_dispatch/routing

1 file changed

+20
-9
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ module Base
470470
# When a pattern points to an internal route, the route's `:action` and
471471
# `:controller` should be set in options or hash shorthand. Examples:
472472
#
473-
# match 'photos/:id' => 'photos#show', via: :get
473+
# match 'photos/:id', to: 'photos#show', via: :get
474474
# match 'photos/:id', to: 'photos#show', via: :get
475475
# match 'photos/:id', controller: 'photos', action: 'show', via: :get
476476
#
@@ -614,18 +614,14 @@ def match(path, options = nil)
614614
#
615615
# mount SomeRackApp, at: "some_route"
616616
#
617-
# Alternatively:
618-
#
619-
# mount(SomeRackApp => "some_route")
620-
#
621617
# For options, see `match`, as `mount` uses it internally.
622618
#
623619
# All mounted applications come with routing helpers to access them. These are
624620
# named after the class specified, so for the above example the helper is either
625621
# `some_rack_app_path` or `some_rack_app_url`. To customize this helper's name,
626622
# use the `:as` option:
627623
#
628-
# mount(SomeRackApp => "some_route", as: "exciting")
624+
# mount(SomeRackApp, at: "some_route", as: "exciting")
629625
#
630626
# This will generate the `exciting_path` and `exciting_url` helpers which can be
631627
# used to navigate to this mounted app.
@@ -649,7 +645,15 @@ def mount(app, options = nil)
649645
MSG
650646
ActionDispatch.deprecator.warn(<<-MSG.squish) if hash_key_app
651647
Mounting an engine with a hash key name is deprecated and
652-
will be removed in Rails 8.1. Please use the at: option instead.
648+
will be removed in Rails 8.1. Please use the `at:` option instead.
649+
650+
Instead of:
651+
652+
mount(SomeRackApp => "some_route")
653+
654+
Please use:
655+
656+
mount SomeRackApp, at: "some_route"
653657
MSG
654658

655659
rails_app = rails_app? app
@@ -1677,7 +1681,6 @@ def draw(name)
16771681
# Matches a URL pattern to one or more routes. For more information, see
16781682
# [match](rdoc-ref:Base#match).
16791683
#
1680-
# match 'path' => 'controller#action', via: :patch
16811684
# match 'path', to: 'controller#action', via: :post
16821685
# match 'path', 'otherpath', on: :member, via: :get
16831686
def match(path, *rest, &block)
@@ -1689,8 +1692,16 @@ def match(path, *rest, &block)
16891692

16901693
ActionDispatch.deprecator.warn(<<-MSG.squish)
16911694
Drawing a route with a hash key name is deprecated and
1692-
will be removed in Rails 8.1. Please use the to: option with
1695+
will be removed in Rails 8.1. Please use the `to:` option with
16931696
"controller#action" syntax instead.
1697+
1698+
Instead of:
1699+
1700+
match "path" => "controller#action`
1701+
1702+
Please use:
1703+
1704+
match "path", to: "controller#action"
16941705
MSG
16951706

16961707
case to

0 commit comments

Comments
 (0)