lundi 28 août 2017

Multiple Select Checkboxes

My app has two primary user roles:

Staff are university employees who fill out Referral Requests with patient details to be sent to Clinicians

Clinicians are private physicians who receive the referral request if they match the criteria detailed by the Staff user.

A Referral Request is basically a form where the Staff details the patient and their needs.

As part of this form, I want to collect information about a patient's gender identity.

I've created a model called Gender and associated genders table and then filled it in with data using seeds.

["Female", "Male", "Non-binary", "Queer", "Transgender", "Not Specified"].each do |g|

Gender.create!(name: g,
                  created_at: Time.zone.now,
                  updated_at: Time.zone.now)

I originally built the form input for gender this way, with patient_gender_id being an integer column in the referral_requests table and genders displayed as a dropdown.

  Patient's Gender Identification
    <%= collection_select( :referral_request, :patient_gender_id, Gender.all, :id, :name, prompt: true) %>

I want to change this to allow the user to select multiple gender options rather than a single one and to use checkboxes instead of a dropdown.

I know I'll need to change my controller among other things, but I keep getting errors when I try:

def referral_request_params
    params.require(:referral_request).permit(:content, :patient_gender_id, 
        :preferred_gender_id, concern_ids: [], insurance_ids: [])

end

I used this migration to try to change the patient_gender_id field to an array of integers, but I'm not sure it worked b/c I don't see anything in my schema file that would indicate that the field is now an array.

  def change
     change_column :referral_requests, :patient_gender_id, :integer, array: true, default: []
  end
end

-How do I change the form, the controller, and if necessary, the schema to accommodate multiple gender selections with checkboxes?

Any help would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire