Search code examples
ruby-on-rails-3activeadminformtasticransackhstore

Activeadmin and Formtastic with HStore column


I am unable to edit or add a new model in activeadmin that has an HStore column due to the following error.

Unable to find input class for hstore

How can I get activeadmin and formtastic to play nice with my HStore column? This question has been asked but I cannot find a definitive answer that allows for adding and editing of the hstore field.

I have used these references so far

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

Filter activeadmin with hstore

and

https://github.com/gregbell/active_admin/issues/2032


Solution

  • For anyone who happens to stumble across this, I was able to use the activeadmin_hstore_editor gem for this purpose, which gives a way to input arbitrary json into an input field.