diff --git a/app/controllers/time_slots_controller.rb b/app/controllers/time_slots_controller.rb index bcb3564..5f19249 100644 --- a/app/controllers/time_slots_controller.rb +++ b/app/controllers/time_slots_controller.rb @@ -1,6 +1,16 @@ # frozen_string_literal: true class TimeSlotsController < ApplicationController + def filter + @schedule = Schedule.find(params[:schedule_id]) + + @time_slots = TimeSlot.all + @time_slots = @time_slots.where(day: params[:day]) if params[:day].present? + @time_slots = @time_slots.where(slot_type: params[:slot_type]) if params[:slot_type].present? + + redirect_to schedule_time_slots_path(@schedule, day: params[:day], slot_type: params[:slot_type]) + end + def index @time_slots = TimeSlot.all @time_slots = @time_slots.where(day: params[:day]) if params[:day].present? diff --git a/app/views/time_slots/index.html.erb b/app/views/time_slots/index.html.erb index daafebf..35f19cb 100644 --- a/app/views/time_slots/index.html.erb +++ b/app/views/time_slots/index.html.erb @@ -1,18 +1,19 @@ <%= render_navbar("time-slots", @schedule) %> -<%= form_with url: time_slots_path, method: :get, local: true do %> -