Custom ActiveAdmin filter for date range

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?

+4
1

, ransacker. .

:

filter :surveys_updated_at, label: 'By Date Completed', as: :date_range

, , , . , Google, .

  • Ransacker ActiveAdmin. Ransacker by_date_completed_gteq by_date_completed_lteq.

  • ransacker . String Int, .

  • / proc ransacker Arel/SQL, DB.

ransacker:

ransacker :foo do
  "ransacker sql code"
end

"SELECT * FROM bar WHERE 'ransacker sql code' = <input>"

ransack :

ransacker :by_date_completed do
  "surveys.updated_at"
end

:

"SELECT * FROM users WHERE surveys.updated_at >= START_DATE AND surveys.updated_at <= END_DATE"
+4

All Articles