title: Rails where with multiple conditions
body: <p>In my application I have multiple user roles defined using an enum:</p>
  
  <pre><code>enum role: { staff: 0, clinician: 1, admin: 2 }
  </code></pre>
  
  <p>Staff users each belong to a university:</p>
  
  <p><strong>Staff Concern:</strong></p>
  
  <pre><code>require 'active_support/concern'
  
  module StaffUser
    extend ActiveSupport::Concern
  
    included do
      belongs_to :university
      has_many :patients
      has_many :referral_requests
      validates :university_id, presence: true, if: :staff?
    end
  </code></pre>
  
  <p><strong>University Model</strong></p>
  
  <pre><code>class University &lt; ApplicationRecord
    has_many :staffs, -&gt; { where role: :staff}, class_name: "User"
    has_many :clinicians, through: :lists
    has_many :whitelists
    belongs_to :market
  
    validates :market_id, presence: true
  end
  </code></pre>
  
  <p>I have a dropdown select menu for Staff Doctor on a patients/new view where I want to display a list of staff users who belong to the same university as the current user, but I can't seem to get it to work. Currently, the dropdown only contains the prompt text. What am I doing wrong?</p>
  
  <p><strong>patients/new view:</strong></p>
  
  <pre><code>&lt;%= form_for(@patient) do |f| %&gt;
    &lt;%= render 'shared/error_messages', object: f.object %&gt;
    &lt;div class="checkbox"&gt;
  
      &lt;h1&gt;Tell us about your patient&lt;/h1&gt;
  
  
      &lt;h2&gt;Insurance&lt;/h2&gt;
      &lt;% Insurance.all.each do |insurance| %&gt;
        &lt;%= check_box_tag "patient[insurance_ids][]", insurance.id, @patient.insurance_ids.include?(insurance.id), id: dom_id(insurance) %&gt;
        &lt;%= label_tag dom_id(insurance), insurance.name %&gt;&lt;br&gt;
      &lt;% end %&gt;
  
      &lt;h2&gt;Presenting Concerns&lt;/h2&gt;
      &lt;% Concern.all.each do |concern| %&gt;
        &lt;%= check_box_tag "patient[concern_ids][]", concern.id, @patient.concern_ids.include?(concern.id), id: dom_id(concern) %&gt;
        &lt;%= label_tag dom_id(concern), concern.name %&gt;&lt;br&gt;
      &lt;% end %&gt;
  
      &lt;h2&gt;Staff Doctor&lt;/h2&gt;  
  
         &lt;%= select_tag "patient[staff_doctor_id]", options_from_collection_for_select(User.where("role = ? AND university_id = ?", "staff", @user.university_id), "id", "name"), prompt: "Select this patient's therapist" %&gt;
  
    &lt;/div&gt;
  
    &lt;%= f.submit "Submit", class: "btn btn-primary" %&gt;
  &lt;% end %
  </code></pre>
  
  <p><strong>Patients Controller:</strong></p>
  
  <pre><code>class PatientsController &lt; ApplicationController
      before_action :require_login
  
  def new
      @user = current_user
      @patient = current_user.patients.build
  end
  
  def index
      authorize Patient
      @patients = policy_scope(Patient)
  end
  
  def show
      @patient = Patient.find(params[:id])
  end
  
  def edit
      @patient = Patient.find(params[:id])
  end
  
  def update
      @patients = Patient.all
      @patient = Patient.find(params[:id])
      if @patient.update_attributes(patient_params)
          flash[:success] = "Patient Updated!"
          render 'patients/index'
      else
          render "edit"
      end
  end
  
  
  def create
      @patient = current_user.patients.build(patient_params)
      if @patient.save
          flash[:success] = "Patient Created!"
          redirect_to new_referral_request_path(patient_id: @patient.id)
      else
          Rails.logger.info(@patient.errors.inspect)
          render 'patients/new'
  end
  end
  
  
  private
  
  def patient_params
      params.require(:patient).permit(:age, :staff_doctor_id, :user_id, insurance_ids: [], gender_ids: [], concern_ids: [], race_ids: [])
  
  end
  end
  </code></pre>