2016-06-12 116 views
0

我有用户,PatientProfile和DoctorProfile之间的多态关系。我正在尝试为Review创建RESTful路由。最佳做法是什么?Rails多态RESTful路由

class User 
belongs_to :profile, polymorphic: true 

class PatientProfile 
has_one :user, as: :profile 
has_many :reviews 

class DoctorProfile 
has_one :user, as: :profile 
has_many :reviews 

class Review 
belongs_to :patient_profile 
belongs_to :doctor_profile 

一种方法是创建两个DoctorProfilePatientProfile而不是使用Users不同的路线。这种方法的缺点是,你需要有2条评论控制器DoctorProfileReviewsControllerPatientProfileReviewsController

resources :patient_profile 
    resources :reviews 
end 
resources :doctor_profile 
    resources :reviews 
end 

什么是组织给了这些车型REST API最好的方法?

回答

1
\doctors\:id\reviews 
\doctors\:id\reviews\:id 
\patients\:id\reviews 
\patients\:id\reviews\:id 
\reviews\:id 

每个医生应该能够有它的评论质疑,每个病人应该能够有它的评论质疑,每次审查应能进行查询。

如果每个资源都是系统的活动部分,您最终可能会最终使用所有资源,所以使每个资源都可以访问。