title: Improving active record queries
body: <p>I have the following queries, i know it looks very bad.</p>
  
  <p>Note: I added them to instance variables because i will use them inside highcharts js library so each instance variable will represent a single column/bar/line inside highcharts js</p>
  
  <p>tickets_controller.rb</p>
  
  <pre><code>def priorities_chart
      priority_base = Ticket.includes(:priority)
      @high_tickets_counter = priority_base.where(priorities: {name: 'High'}).count
      @medium_tickets_counter = priority_base.where(priorities: {name: 'Medium'}).count
      @low_tickets_counter = priority_base.where(priorities: {name: 'Low'}).count
    end
  
    def statuses_chart
      status_base = Ticket.includes({ticket_statuses: :status})
      @open_tickets_counter = status_base.where(statuses: {ticket_status: 'Open'}).count
      @in_progress_tickets_counter = status_base.where(statuses: {ticket_status: 'In Progress'}).count
      @pending_tickets_counter = status_base.where(statuses: {ticket_status: 'Pending'}).count
      @solved_tickets_counter = status_base.where(statuses: {ticket_status: 'Solved'}).count
      @closed_tickets_counter = status_base.where(statuses: {ticket_status: 'Closed'}).count
    end
  
    def subjects_chart
      subject_base = Ticket.includes({student: :subjects})
      @subject_1_counter = subject_base.where(subjects: {subject_title: 'Subject 1'}).count
      @subject_2_counter = subject_base.where(subjects: {subject_title: 'Subject 2'}).count
      @subject_3_counter = subject_base.where(subjects: {subject_title: 'Subject 3'}).count
      @subject_4_counter = subject_base.where(subjects: {subject_title: 'Subject 4'}).count
      @subject_5_counter = subject_base.where(subjects: {subject_title: 'Subject 5'}).count
    end
  </code></pre>
  
  <p>I need to improve this ugly look and achieving the following:</p>
  
  <p>1- what if i have another subjects with different names or more than 10 subjects , i need a query to handle this without specifying the subject title as i am doing here.</p>
  
  <p>2- is there a better way to write priorities_chart and statuses_chart ?</p>