I have two models, Clinician
and Patient
. A clinician
has_many: patients
and a patient
belongs_to :clinician
.
Besides the clinician that a patient belongs_to
a patient also has a column called shared_with
, which is a string holding an array of clinician.id
. This is done using serialize :shared_with, Array
.
I would like to be able to select from a drop down of clinician's full_name
for only clinicians who's id
is included in the shared_with
array.
<%= form_for [@clinician, @comment] do |form| %>
<div class="form-group">
<%= form.label :clinician_id %>
<%= form.collection_select :clinician_id, Clinician.all.order("last_name asc"), :id, :full_name, class: "form-control" %>
</div>
<div class="form-group">
<%= form.label :general_comment %>
<%= form.text_area :general_comment, class: "form-control", rows: 5, placeholder: "Leave a comment" %>
</div>
<%= form.button 'Submit Comment', class: "btn btn-u btn-success" %>
Where I currently have Clinician.all.order("last_name asc")
I would like to sort it so that I only have this shorter list.
I think it will be something like replacing what I have now with @clinicians
and defining that as:
@patient = Patient.find_by(user_id: current_user.patient.id).shared_with
@clinicians = a list of clinicians where id: @patient.each
And using some method that is able to do this for me.
Any advice would be appreciated. Thanks