class DashboardController < ApplicationController def index joint_column = 'joint' # Grab distinct values for dropdown filters @available_joints = Joint.distinct.pluck(joint_column) # Fetch initial records @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 end end private def filter_records if params.include?(:joint) records = Joint.all records = records.where(joint: params[:joint]) records else [] end end end