Created
December 26, 2013 12:10
-
-
Save tacettin/8132993 to your computer and use it in GitHub Desktop.
Rails namespace routes and custom action on resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You need to add a collection | |
namespace :api do | |
namespace :v1 do | |
resources :users do | |
collection do | |
get 'all' | |
end | |
end | |
resources :sessions | |
end | |
end | |
The namespace and resources method calls create the hierarchy; a route nested with the resource :users block will take on the path of it's ancestors. The collection creates nested routes on the resource collection instead of single instances of the resource. | |
/api/v1/users/all | |
Recommended Reading: http://guides.rubyonrails.org/routing.html#adding-collection-routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment