Skip to content

Commit c40ff50

Browse files
committed
Deprecate multiple path route mapping
Drawing routes with multiple paths complicates route drawing enough to warrant deprecation. Transitioning the routing mapper to use keywords would result in a 1.25-1.5x improvement in speed, and it would be substantially easier to do if we drop this feature. Most developers draw one path per route, so this feature is likely seldom used. Developers may also leverage with_options or a loop to make drawing easier. ```ruby get "/users", "/other_path", to: "users#index" get "/users", to: "users#index" get "/other_path", to: "users#index" ```
1 parent 91f0bc4 commit c40ff50

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

actionpack/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
* Deprecate drawing routes with multiple paths to make routing faster.
2+
You may use `with_options` or a loop to make drawing multiple paths easier.
3+
4+
```ruby
5+
# Before
6+
get "/users", "/other_path", to: "users#index"
7+
8+
# After
9+
get "/users", to: "users#index"
10+
get "/other_path", to: "users#index"
11+
```
12+
13+
*Gannon McGibbon*
14+
115
* Make `http_cache_forever` use `immutable: true`
216

317
*Nate Matykiewicz*

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,11 @@ def path_scope(path)
19351935
end
19361936

19371937
def map_match(paths, options)
1938+
ActionDispatch.deprecator.warn(<<-MSG.squish) if paths.count > 1
1939+
Mapping a route with multiple paths is deprecated and
1940+
will be removed in Rails 8.1. Please use multiple method calls instead.
1941+
MSG
1942+
19381943
if (on = options[:on]) && !VALID_ON_OPTIONS.include?(on)
19391944
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
19401945
end

actionpack/test/dispatch/routing_test.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ def test_projects_people
763763

764764
member do
765765
put :accessible_projects
766-
post :resend, :generate_new_password
766+
post :resend
767+
post :generate_new_password
767768
end
768769
end
769770
end
@@ -812,7 +813,8 @@ def test_projects_posts
812813
draw do
813814
resources :projects do
814815
resources :posts do
815-
get :archive, :toggle_view, on: :collection
816+
get :archive, on: :collection
817+
get :toggle_view, on: :collection
816818
post :preview, on: :member
817819

818820
resource :subscription
@@ -1533,8 +1535,10 @@ def test_index
15331535
end
15341536

15351537
def test_match_with_many_paths_containing_a_slash
1536-
draw do
1537-
get "get/first", "get/second", "get/third", to: "get#show"
1538+
assert_deprecated(ActionDispatch.deprecator) do
1539+
draw do
1540+
get "get/first", "get/second", "get/third", to: "get#show"
1541+
end
15381542
end
15391543

15401544
get "/get/first"
@@ -1570,9 +1574,11 @@ def test_match_shorthand_inside_namespace
15701574
end
15711575

15721576
def test_match_shorthand_with_multiple_paths_inside_namespace
1573-
draw do
1574-
namespace :proposals do
1575-
put "activate", "inactivate"
1577+
assert_deprecated(ActionDispatch.deprecator) do
1578+
draw do
1579+
namespace :proposals do
1580+
put "activate", "inactivate"
1581+
end
15761582
end
15771583
end
15781584

0 commit comments

Comments
 (0)