Reputation: 3090
I have the following route:
resources :articles, except: [:index] do
collection do
get 'author/:id/articles' => 'articles#index', as: 'index_articles'
end
end
This results in:
GET /api/v1/articles/:id/author/:id/articles(.:format)
How can I turn this into the following?:
GET /api/v1/author/:id/articles(.:format)
Upvotes: 2
Views: 49
Reputation: 3984
Write this
get 'author/:id/articles' => 'articles#index', as: 'index_articles'
Outside the resources :articles
block.
Upvotes: 0
Reputation: 76784
# config/routes.rb
resources :articles, except: [:index]
resources :authors, path: "author", only: [] do
resources :articles, only: :index, on: :member #-> url.com/author/:id/articles
end
Upvotes: 1