Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow setting a symbol as path in scope on routes

Was surprising found that this example doesn't work:

  scope :api do
    resources :users
  end

and the right form to use it is:

  scope 'api' do
    resources :users
  end

I think this should work similary as `namespace` where both are allowed.
These two are equivalent:

  namespace :api do
    resources :users
  end

  namespace 'api' do
    resources :user
  end
  • Loading branch information...
commit 0d3a9e8a6b30d2bae09209eecfb3380f8c600eb6 1 parent 0134ca6
Guillermo Iguaran authored
22 actionpack/CHANGELOG.md
Source Rendered
... ... @@ -1,5 +1,27 @@
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:
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -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] ||= {}
20 actionpack/test/dispatch/routing_test.rb
@@ -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

0 comments on commit 0d3a9e8

Please sign in to comment.
Something went wrong with that request. Please try again.