我想設置的格式爲一個GET端點:Ruby on Rails的 - 嵌套路線集合
api/v1/users/types/{type_id}
例子:> api/v1/users/types/10
我當前的路由看起來是這樣的:
Rails.application.routes.draw do
namespace :api do
namespace :v1 do
resources :users do
collection do
# other routes in the same namespace
get "sync"
post "register"
# my attempt at making another collection for `types`
collection do
get "types"
end
end
end
end
end
end
這是不正確的,它會引發一個錯誤:ArgumentError: can't use collection outside resource(s) scope
。根據我的要求,正確的路線格式是什麼?
什麼控制器方法應該處理的要求嗎?你關心這個參數是叫'type_id'還是隻叫'id'。 – spickermann
@spickermann沒有真正關注這個參數名稱 – Dinuka