我有这些路线:
namespace :api, defaults: {format: :json} do
namespace :v1 do
resources :cars
resources :users, only: [:create] do
member do
resources :cars, controller: "user/cars"
resources :friends, controller: "user/friends"
resources :drink, controller: "user/drinks"
end
end
end
end
有没有办法在那些嵌套资源上抽象非干控制器定义?
编辑:
我理想的示例输出是:
namespace:api,默认值:{format :: json} do namespace:v1 do
resources :cars
resources :users, only: [:create] do
member do
resources :cars
resources :friends
resources :drink
end
end
end
端
并且三个嵌套资源使用之前声明的控制器
答案 0 :(得分:0)
namespace :api, defaults: {format: :json} do
namespace :v1 do
resources :users, only: [:create]
resources :cars
scope "users/:id", as: "users", module: "users" do
resources :cars
resources :friends
resources :drink
end
end
end