Skip to content

Instantly share code, notes, and snippets.

@tacettin
Created December 26, 2013 12:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacettin/8132993 to your computer and use it in GitHub Desktop.
Save tacettin/8132993 to your computer and use it in GitHub Desktop.
Rails namespace routes and custom action on resource
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