Filter activeadmin with hstore

前端 未结 2 1590
萌比男神i
萌比男神i 2021-01-24 04:10

I would like to use activeadmin filters with hstore:

In model I have got column amenities with Room.

I would like to do sth like this:

fil

2条回答
  •  走了就别回头了
    2021-01-24 05:06

    With latest activeadmin (which uses ransack instead of meta_search) it's possible to define a custom ransacker for hstore field in a model:

    class Room < ActiveRecord::Base
      store_accessor :options, :amenities
    
      ransacker :amenities do |parent|
        Arel::Nodes::InfixOperation.new('->', parent.table[:options], 'amenities')
      end
    end
    

    Then it can be used in activeadmin for filtering:

    ActiveAdmin.register Room do
      filter :amenities_eq, label: 'Amenities', as: :select # ...
    end
    

提交回复
热议问题