我有以下路线:
resources :articles, except: [:index] do
collection do
get 'author/:id/articles' => 'articles#index', as: 'index_articles'
end
end
这导致:
GET /api/v1/articles/:id/author/:id/articles(.:format)
如何将其转换为以下内容?:
GET /api/v1/author/:id/articles(.:format)
答案 0 :(得分:1)
# 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
答案 1 :(得分:0)
写这个
get 'author/:id/articles' => 'articles#index', as: 'index_articles'
在resources :articles
区块之外。