简体   繁体   English

路由多个配置文件视图

[英]Routing for multiple profile views

I no have idea how to implement display of the multiple user's profile. 我不知道如何实现多用户个人资料的显示。 I use STI inheritance to for few types of person. 我将STI继承用于几种类型的人。

What I want? 我想要的是?

I want to create the simplest routing for each type of person, and possibility to display and edit profile for each type of person. 我想为每种类型的人创建最简单的路由,并为每种类型的人显示和编辑个人资料。 Now I have this: 现在我有这个: 在此处输入图片说明

I thought about profile view(backend_people_profile) only for people model, and update_profile for each type. 我只考虑了人物模型的个人资料视图(backend_people_profile),每种类型的update_profile。 Is it correct? 这是正确的吗? Now I have too many repetitive paths. 现在,我有太多重复的路径。

routes.rb 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

I would start with the simplest possible setup. 我将从最简单的设置开始。 In this case you would only have the full CRUD routes for the base people type. 在这种情况下,您只有基本people类型的完整CRUD路线。 This avoids cluttering your API with a ton of routes that perform the exact same thing. 这样可以避免大量执行相同操作的路由使API混乱。

For each subtype you simply have an index action which is somewhat like: 对于每个子类型,您只需执行一个类似于以下操作的索引操作:

GET /people?type=trainer

You may want to consider if you really need separate routes for profiles - unless you need two significantly different representations you can get by with the conventional CRUD routes: 您可能要考虑是否确实需要为配置文件使用单独的路由-除非您需要使用常规CRUD路由可以获得两种截然不同的表示形式,否则:

GET|POST         /people
GET|DELETE|PATCH /people/:id
GET              /people/:id/new
GET              /people/:id/edit

The other case would be an app where users are CRUD:ed by admins where you need a separate interface for the regular user signup. 另一种情况是一个应用程序,其中用户被管理员CRUD:由管理员管理,您需要一个单独的界面来进行常规用户注册。 In that case you might to do it like so: 在这种情况下,您可以这样做:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM