File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
lib/action_dispatch/routing Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
1
## Rails 4.0.0 (unreleased) ##
2
2
3
+ * Allow setting a symbol as path in scope on routes. This is now allowed:
4
+
5
+ scope : api do
6
+ resources : users
7
+ end
8
+
9
+ also is possible pass multiple symbols to scope to shorten multiple nested scopes:
10
+
11
+ scope : api do
12
+ scope : v1 do
13
+ resources : users
14
+ end
15
+ end
16
+
17
+ can be rewritten as:
18
+
19
+ scope : api , : v1 do
20
+ resources : users
21
+ end
22
+
23
+ * Guillermo Iguaran*
24
+
3
25
* Fix error when using a non-hash query argument named "params" in ` url_for ` .
4
26
5
27
Before:
Original file line number Diff line number Diff line change @@ -644,7 +644,7 @@ def scope(*args)
644
644
options = args . extract_options!
645
645
options = options . dup
646
646
647
- options [ :path ] = args . first if args . first . is_a? ( String )
647
+ options [ :path ] = args . flatten . join ( '/' ) if args . any?
648
648
recover = { }
649
649
650
650
options [ :constraints ] ||= { }
Original file line number Diff line number Diff line change @@ -370,6 +370,14 @@ def self.call(params, request)
370
370
scope :path => 'api' do
371
371
resource :me
372
372
get '/' => 'mes#index'
373
+ scope :v2 do
374
+ resource :me , as : 'v2_me'
375
+ get '/' => 'mes#index'
376
+ end
377
+
378
+ scope :v3 , :admin do
379
+ resource :me , as : 'v3_me'
380
+ end
373
381
end
374
382
375
383
get "(/:username)/followers" => "followers#index"
@@ -1467,6 +1475,18 @@ def test_path_scope
1467
1475
assert_equal 'mes#index' , @response . body
1468
1476
end
1469
1477
1478
+ def test_symbol_scope
1479
+ get '/api/v2/me'
1480
+ assert_equal 'mes#show' , @response . body
1481
+ assert_equal '/api/v2/me' , v2_me_path
1482
+
1483
+ get '/api/v2'
1484
+ assert_equal 'mes#index' , @response . body
1485
+
1486
+ get '/api/v3/admin/me'
1487
+ assert_equal 'mes#show' , @response . body
1488
+ end
1489
+
1470
1490
def test_url_generator_for_generic_route
1471
1491
get 'whatever/foo/bar'
1472
1492
assert_equal 'foo#bar' , @response . body
You can’t perform that action at this time.
0 commit comments