我定义了以下路线:
resources :patients do
collection do
get 'import' => :new_import
post 'import' => :import
end
end
resources :course_enrollments, :only => [:index, :show] do
member do
get 'completed'
post 'complete_course_enrollment'
end
end
我希望能够显示课程注册并为患者添加课程注册。该路由应该作为成员操作“/ patients /:id / enrollments”和/ patients / id:/ add_enrollment吗?
或者我应该筑巢路线吗?
以下是模型:
class Patient < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
has_many :enrollments, :dependent => :destroy
has_many :clients, :through => :enrollments
has_many :course_requests, :dependent => :destroy
has_many :course_enrollments, :dependent => :destroy
has_many :courses, :through => :course_enrollments
has_many :quiz_attempts, :dependent => :destroy
has_many :patient_course_steps, :dependent => :destroy
has_many :survey_results, :dependent => :destroy
accepts_nested_attributes_for :user
accepts_nested_attributes_for :enrollments
attr_accessible :user_attributes, :client_ids, :enrollments_attributes, :insurance
validate :has_clients?
end
class CourseEnrollment < ActiveRecord::Base
belongs_to :patient
belongs_to :course
attr_accessible :patient_id, :course_id, :started, :completed, :last_viewed
validates_uniqueness_of :patient_id, :scope => :course_id
end
答案 0 :(得分:1)
resources :patients do
resources :course_enrollments, :as => :enrollments
collection do
get 'import' => :new_import
post 'import' => :import
end
end
根据需要为patient_course_enrollments_path
提供/patients/:id/enrollments
。