2016-06-12 73 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 

每個醫生應該能夠有它的評論質疑,每個病人應該能夠有它的評論質疑,每次審查應能進行查詢。

如果每個資源都是系統的活動部分,您最終可能會最終使用所有資源,所以使每個資源都可以訪問。