I need to create a custom ActiveAdmin filter for a Date Range which belongs to another resource. I want to filter a list of users by a date range of when they completed a survey.
I've declared a custom filter in the ActiveAdmin DSL like so:
filter :by_date_completed, label: 'By Date Completed', as: :date_range
This makes me a nice date range in active admin to restrict my users by. All good.
I haven't been able to find much documentation on how to do this but in my user model I've tried to create a ransacker to handle the filter.
ransacker :by_date_completed, {
formatter: proc { |start_date, end_date|
time_range = start_date..end_date
users = User.joins(:surveys).where(surveys: { updated_at: time_range})
users = users.map(&:id)
users.present? ? users : nil
},
callable: proc { |parent|
parent.table[:id]
}
}
But ActiveAdmin passes the date ranges to the filter one at a time and so I can't get a range to search by?
What am I meant to do in this scenario? Am I going about the whole problem in the wrong way?