多个配置文件视图的路由
Routing for multiple profile views
我不知道如何实现显示多个用户的个人资料。
我将 STI 继承用于少数类型的人。
我想要什么?
我想为每种类型的人创建最简单的路由,以及显示和编辑每种类型的人的个人资料的可能性。现在我有这个:
我只考虑人物模型的个人资料视图 (backend_people_profile),每种类型都考虑 update_profile。这是正确的吗?现在我有太多重复的路径。
routes.rb
namespace :backend do
resources :managers, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :clients, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :receptionists, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :trainers, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :lifeguards, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
end
namespace :backend do
resources :people
[:clients, :receptionists, :trainers, :lifeguards].each |type| do
get type, to: "people#index"
end
end
我将从最简单的设置开始。在这种情况下,您将只有基本 people
类型的完整 CRUD 路由。这避免了让你的 API 被大量执行完全相同的事情的路由弄得乱七八糟。
对于每个子类型,您都有一个索引操作,有点像:
GET /people?type=trainer
您可能需要考虑您是否真的需要配置文件的单独路由 - 除非您需要两种截然不同的表示形式,否则您可以使用传统的 CRUD 路由:
GET|POST /people
GET|DELETE|PATCH /people/:id
GET /people/:id/new
GET /people/:id/edit
另一种情况是用户由管理员 CRUD:ed 管理的应用程序,您需要一个单独的界面来进行常规用户注册。在那种情况下,您可以这样做:
namespace :backend do
resources :people
[:clients, :receptionists, :trainers, :lifeguards].each |type| do
get type, to: "people#index"
end
end
# public facing route
resources :registrations, only: [:new, :create, :show, :edit, :update]
我不知道如何实现显示多个用户的个人资料。 我将 STI 继承用于少数类型的人。
我想要什么?
我想为每种类型的人创建最简单的路由,以及显示和编辑每种类型的人的个人资料的可能性。现在我有这个:
我只考虑人物模型的个人资料视图 (backend_people_profile),每种类型都考虑 update_profile。这是正确的吗?现在我有太多重复的路径。
routes.rb
namespace :backend do
resources :managers, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :clients, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :receptionists, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :trainers, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
resources :lifeguards, except: [:new, :create] do
get '/profile', to: 'people#show_profile'
end
end
namespace :backend do
resources :people
[:clients, :receptionists, :trainers, :lifeguards].each |type| do
get type, to: "people#index"
end
end
我将从最简单的设置开始。在这种情况下,您将只有基本 people
类型的完整 CRUD 路由。这避免了让你的 API 被大量执行完全相同的事情的路由弄得乱七八糟。
对于每个子类型,您都有一个索引操作,有点像:
GET /people?type=trainer
您可能需要考虑您是否真的需要配置文件的单独路由 - 除非您需要两种截然不同的表示形式,否则您可以使用传统的 CRUD 路由:
GET|POST /people
GET|DELETE|PATCH /people/:id
GET /people/:id/new
GET /people/:id/edit
另一种情况是用户由管理员 CRUD:ed 管理的应用程序,您需要一个单独的界面来进行常规用户注册。在那种情况下,您可以这样做:
namespace :backend do
resources :people
[:clients, :receptionists, :trainers, :lifeguards].each |type| do
get type, to: "people#index"
end
end
# public facing route
resources :registrations, only: [:new, :create, :show, :edit, :update]