How to filter IS NULL in ActiveAdmin?

前端 未结 5 774
迷失自我
迷失自我 2020-12-25 14:14

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 implem

5条回答
  •  佛祖请我去吃肉
    2020-12-25 14:55

    With ransackable scopes:

    On the ActiveAdmin resource definition:

    filter :map_id, :label => 'Assigned', as: :select, :collection => [['Is Null', 'none'], ['Not null', 'present']]
    

    On your model:

    scope :by_map_id, ->(id) { (id == 'none' ? where(map_id: nil) : where('map_id IS NOT NULL')) }
    
    def self.ransackable_scopes(_auth_object = nil)
      %i[by_map_id]
    end
    

提交回复
热议问题