Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails丰富关联-覆盖到关联模型_Ruby On Rails_Ruby_Model Associations - Fatal编程技术网

Ruby on rails Rails丰富关联-覆盖到关联模型

Ruby on rails Rails丰富关联-覆盖到关联模型,ruby-on-rails,ruby,model-associations,Ruby On Rails,Ruby,Model Associations,假设我们有三个模型患者、护士和他们的协会模型预约 本周,所有患者都必须与护士会面 一个病人有许多护士,一个护士有许多病人。同样,患者有许多预约,但每位护士只有一次,护士有许多预约,但每位患者只有一次 class Patient < ActiveRecord::Base has_many :appointments has_many :nurses, :through => :appointments end class Nurse < ActiveRecord::

假设我们有三个模型患者、护士和他们的协会模型预约

本周,所有患者都必须与护士会面

一个病人有许多护士,一个护士有许多病人。同样,患者有许多预约,但每位护士只有一次,护士有许多预约,但每位患者只有一次

class Patient < ActiveRecord::Base 
  has_many :appointments
  has_many :nurses, :through => :appointments
end


class Nurse < ActiveRecord::Base 
  has_many :appointments
  has_many :patients, :through => :appointments
end


class Appointment < ActiveRecord::Base
  belongs_to :patient
  belongs_to :nurse
end
但这不是我想要的。我希望护士能够修改此关联,并阻止患者更改任何内容


我应该不使用丰富的关联吗?

我假设您的问题是关于如何使用这些关联。保留约会后,您可以调用和修改约会记录,如下所示:

# current_nurse is the nurse using the system and reporting
appt = current_nurse.appointments.where(:patient_id => params[:patient_id]).first
appt.update_attribute :present, true
为了防止患者访问和修改预约,您需要一种身份验证机制,例如。然后只授予护士访问系统的权限

appt = Appointment.new
patient = Patient.new
nurse = Nurse.new

patient.appointments << appt
nurse.appointments << appt
appt.present = true
# current_nurse is the nurse using the system and reporting
appt = current_nurse.appointments.where(:patient_id => params[:patient_id]).first
appt.update_attribute :present, true