Custom Active Admin filter with ransacker

I am trying to write my own method for the ActiveAdmin Users model. It is my understanding that I have to use ransacker for this.

I would like you to have a selection with the following that appears in the UI dropdown, for example:

Aug 2010-Aug 2011
Aug 2011-Aug 2012
Aug 2012-Aug 2013
Aug 2013-Aug 2014
Aug 2014-Aug 2015
Aug 2015-Aug 2016

      

Here are my tables where I need to grab information.

Users
------
id (int)

school_participants
-------------------
user_id (int)
start_date (datetime)

      

SchoolParticipant is owned by the user , the user has many school_participants.

I first tried to do something like this in ActiveAdmin filter

  filter :participant_schools_start_date, :label => "School Year", :as => :select, :collection => [['2010', '2010-08-15'], ['2011', '2013-08-15']]

      

Just to see what we get in the forms, but I need a way to pass the range in the select fields, but apparently you can only pass one value at a time. The first item (2010) in this array is displayed in the UI, and the second item (2010-08-15) is what is passed as a value.

Basically I am trying to query between these ranges

**ON Selection in a drop down**                   **Query I want**
         Aug 2010-Aug 2012 a query between   2010-08-15 to 2011-08-15
         Aug 2011-Aug 2012                   2011-08-15 to 2012-08-15
         Aug 2012-Aug 2013                   2012-08-15 to 2013-08-15
         Aug 2013-Aug 2014                   2013-08-15 to 2014-08-15
         Aug 2014-Aug 2015                   2014-08-15 to 2015-08-15
         Aug 2015-Aug 2016                   2015-08-15 to 2016-08-15 

      

I tried to play around with procs and lambdas using some resources I found like this

http://nikhgupta.com/code/activeadmin/custom-filters-using-ransacker-in-activeadmin-interfaces

and

http://cavewall.jaguardesignstudio.com/2014/05/01/activeadmin-filters-with-ransack/

Any thought? Not sure how to do it.

+3


source to share





All Articles