Awesome E

Ruby code posted by Chang
created at 11 Jan 05:00

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Clinics::DashboardsController < ApplicationController
  before_action do
    set_current_clinic(params[:clinic_id])
  end

  def index
    if current_clinic.belongs_to?(current_user)
      if current_user.has_role? 'doctor', current_clinic
        schedule = current_clinic.schedule
        @doctor = current_user.doctors.where(clinic_id: current_clinic.id)
        @date = params[:date] ? Date.parse(params[:date]) : Date.today
        @slots_by_date = schedule.prep_slots(@doctor, @date) unless schedule.blank?
        @todays_slot = @doctor.first.slots.where('starts_at > ?', Date.today.beginning_of_day.to_time)
        @appointments = @todays_slot.first.appointments.page(params[:page]).per(10) unless @todays_slot.blank?
      end
    else
      flash.alert = "You do not have the right to visit this page."
      redirect_to root_path
    end
  end
end
885 Bytes in 2 ms with coderay