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

각각의 의사가이 리뷰 조회 있어요 가질 수 있어야한다, 각 환자는 리뷰 조회, 각각의 검토를 조회 할 수 있어야 있어요 가질 수 있어야한다.

모든 리소스를 액세스 할 수있게하는 것이 좋습니다. 각 리소스가 시스템의 활성 부분 인 경우 나중에 모든 리소스를 사용할 수 있습니다.