gpt4 book ai didi

ruby-on-rails - 如何过滤或限定表格中的医生以仅列出属于组织的医生?

转载 作者:行者123 更新时间:2023-12-04 07:37:21 25 4
gpt4 key购买 nike

创建预约时,假设组织“ABC”,我还可以看到属于其他组织的医生。它假设只列出来自“ABC”的医生,而不是其他人。我该怎么办。

谢谢。

我的预约表:

<%= simple_form_for(@appointment, :html => { :class => 'form-horizontal' }) do |f| %>
<div class="form-inputs">
<%= f.hidden_field :patient_id %>
<%= f.association :physician, :label_method => :first_name, :include_blank => false, :as => :radio_buttons, :required => true %>
<%= f.hidden_field :appointment_date, :value => DateTime.now %>
<%= f.hidden_field :organization_id, :value => current_user.organization_id%>
</div>

<div class="form-actions">
<%= f.button :submit, "Create Appointment" %>
</div>
<% end %>

我的模型:

/app/models/physician.rb

class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
belongs_to :organization

attr_accessible :physician_name, :organization_id
end

/app/models/appointment.rb

class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
belongs_to :organization

attr_accessible :physician_id, :patient_id, :appointment_date, :state, :organization_id
end

/app/models/patient.rb

class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, :through => :appointments
belongs_to :organization

attr_accessible :patient_name, :organization_id
end

我的 Controller :

/app/controllers/appointment_controller.rb

class AppointmentsController < ApplicationController
def new
@appointment = Appointment.new
@appointment.patient_id = params[:patient_id]
end

def create
@appointment = Appointment.new(params[:appointment])

if @appointment.save
flash[:notice] = "New appointment record created"
redirect_to dashboards_path
else
render 'new'
end
end
end

最佳答案

这是因为 simple_form 不知道您的作用域。如果你告诉它:

<%= f.association :phyisician %>

它将简单地列出数据库中所有可用的医生。

解决方案是给它你想要显示的医生的集合,例如你可以写:

<%= f.association :physician,
:collection => @appointment.patient.organization.physicians,
:label_method => :first_name,
:include_blank => false,
:as => :radio_buttons,
:required => true %>

关于ruby-on-rails - 如何过滤或限定表格中的医生以仅列出属于组织的医生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11916137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com