[英]Rails nested routes with controller
I have these routes: 我有以下路线:
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
Is there a way to abstract the non-dry controller definition on those nested resources? 有没有办法在这些嵌套资源上抽象非干控制器定义?
EDIT: 编辑:
my ideal example output is: 我理想的示例输出是:
namespace :api, defaults: {format: :json} do namespace :v1 do 名称空间:api,默认值:{format::json}执行名称空间:v1执行
resources :cars
resources :users, only: [:create] do
member do
resources :cars
resources :friends
resources :drink
end
end
end
end 结束
and that the three nested resources use that controller previously stated 并且三个嵌套资源使用了先前说明的控制器
finally after research I came up with this: 经过研究,我终于想到了:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.