diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c03d033..585ea9a 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,27 +1,25 @@ class DashboardController < ApplicationController def index joint_column = 'joint' - # Grab distinct values for dropdown filters @available_joints = Joint.distinct.pluck(joint_column) - - # Fetch initial records + @available_data @records = filter_records respond_to do |format| - format.html # Renders app/views/dashboards/index.html.erb - format.json { render json: @records } # Returns filtered data as JSON for JS + format.html + format.json { render json: @records } end end private def filter_records - if params.include?(:joint) - records = Joint.all - records = records.where(joint: params[:joint]) - records + # Using .where(joint: params[:joint]) handles both present and nil values gracefully + if params[:joint].present? + Joint.where(joint: params[:joint]) else - [] + # Return empty array if no joint selected to avoid loading thousands of records + [] end end end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index b1024df..d69079b 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -1,88 +1,164 @@ -