如何创建这条路线?

时间:2016-01-29 09:00:13

标签: ruby-on-rails ruby ruby-on-rails-4 routes

我有以下路线:

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)  

2 个答案:

答案 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区块之外。