How to filter IS NULL in ActiveAdmin?

Mahmoud M. Abdel-Fattah picture Mahmoud M. Abdel-Fattah · Aug 20, 2012 · Viewed 7.9k times · Source

I've a table with an integer column called "map_id", I want to add an activeadmin filter to filter if this column IS NULL or IS NOT NULL.

How could this be implemented ?

I tried the following filter

filter :map_id, :label => 'Assigned', :as => :select, :collection => {:true => nil, :false => ''}

But, I get the following error message :

undefined method `map_eq' for #

Answer

Avram Score picture Avram Score · Jan 5, 2015

If anyone is happening on this thread belatedly, there is now an easy way to filter for null or non null in active admin :

filter :attribute_present, :as => :boolean 
filter :attribute_blank,   :as => :boolean  

It is no longer necessary to add a custom method to the scope to accomplish this.