Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter a boolean column on ActiveAdmin?

This question is related to the ActiveAdmin gem. I'm trying to filter a column that has a boolean type but with no success: filter :column_name and filter :column_name, :as => :boolean don't work.

Any idea?

Thanks!

like image 685
Amokrane Chentir Avatar asked Sep 30 '11 10:09

Amokrane Chentir


2 Answers

filter :column_name, :as => :select will create a drop down with values "Any", "True", "False"

like image 198
lbz Avatar answered Oct 18 '22 19:10

lbz


As of ActiveAdmin 0.6.2, using filter :column_name, as: :select now has the horrible side effect of doing a complete table scan. Plus, its options are now "Any", "true", "false".

For example, if I have a District model with the boolean column enabled then filter :enabled, as: :select generates the query SELECT DISTINCT "districts"."enabled" FROM "districts" ORDER BY enabled asc to obtain the 3 values. My districts table is quite large, so this is clearly not what I want.

OTOH, while I can now use filter :column_name, as: :boolean, it uses a checkbox that defaults to not being checked, which is again not what I want.

To restore the pre-0.6.2 behavior, I had to do this: filter :enabled, as: :select, collection: [["Yes", true], ["No", false]]. ActiveAdmin drops in the "Any" value for me.

like image 30
aec Avatar answered Oct 18 '22 19:10

aec