I need to create my own ActiveAdmin filter for a date range that belongs to another resource. I want to filter the list of users by the date range when they completed the survey.
I declared a custom filter in DSL ActiveAdmin as follows:
filter :by_date_completed, label: 'By Date Completed', as: :date_range
This makes me a good date range in the active admin to limit my users. Things are good.
I was not able to find a lot of documentation on how to do this, but in my user model I tried to create 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 therefore I can not get the range to search on?
What should I do in this scenario? Am I really going to solve the whole problem wrong?