Filter activeadmin using hstore

I would like to use activeadmin filters with hstore:

In the model, I have speakers with a room.

I would like to do this:

filter: convenience,: as =>: select ,: collection => proc {Room.all.map {| g | ranks Facilities}}

+1
source share
2 answers

You can simply create custom Formtastic input for the HATore Datatype. If you do not want the Hstore values ​​to be editable, this should be enough (you can optionally set a read-only input field using input_html_options):

class HstoreInput < Formtastic::Inputs::StringInput

end

This will break attribute values ​​when writing.

+4
source

activeadmin ( ransack meta_search) ransacker hstore :

class Room < ActiveRecord::Base
  store_accessor :options, :amenities

  ransacker :amenities do |parent|
    Arel::Nodes::InfixOperation.new('->', parent.table[:options], 'amenities')
  end
end

activeadmin :

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

All Articles