关于#2,它应该是这样的:
form do |f|
f.inputs 'Physician Details' do
f.input :name
end
f.inputs 'Physician Appointments' do
f.has_many :appointments,
heading: false,
new_record: 'Add new appointment',
remove_record: 'Delete appointment',
allow_destroy: true do |app|
app.input :patient, label: 'Choose the patient', collection: Patient.pluck(:name, :id)
app.input :appointment_date
end
end
关于标题: - 它可以是假的或一些标签(字符串)
关于allow_destroy: -您可以设置它检查用户管理员权限,如此处所示
重要- 在医师模型中,确保有
accepts_nested_attributes_for :appointments, allow_destroy: true
并且,在活动管理模型文件 - admin\physicians.rb - 中设置:
permit_params :name, appointments_attributes: [:patient_id, :_destroy, :id]