Question

When trying to create, view or edit a record in RailsAdmin, hstore columns don't show up. I assume RailsAdmin doesn't cater for this Postgres datatype despite it being supported natively in Rails 4.

Is there a workaround?

Was it helpful?

Solution

The simplest way I found to add hstore fields to Rails Admin is to use the Rails 4 store_accessor in the model and list the fields in the Rails admin config for the model.

class Organization < ActiveRecord::Base
  store_accessor :modules, :internal, :external, :default => 'no'

  rails_admin do
    Organization.stored_attributes[:modules].each do |field|
      configure field
    end
  end
end

I made a full demo available on Github.

The demo also includes support for boolean attributes stored in a hstore field, with Rails Admin checkboxes to edit them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top