railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.9k stars 2.26k forks source link

hstore support #1782

Open migu0 opened 11 years ago

migu0 commented 11 years ago

Awesome gem, thanks for your work.

I have an hstore column (PostgreSQL datatype, supported by default in Rails 4). The column doesn't show up in RailsAdmin. I guess it's not supported? Is there a workaround?

LaurensN commented 10 years ago

+1 Is there a workaround / fix available ?

scarfacedeb commented 10 years ago

I think the best solution would be to create a custom field type. Also, you can take a look at this example of a field type for serialized column: https://github.com/bbenezech/blog_admin/blob/1c06298f8330cdbbfba411e3b174f8fca04e7f6d/app/models/blog/post.rb https://github.com/bbenezech/blog_admin/blob/master/lib/rails_admin/metadata.rb

epinault commented 10 years ago

Did that solution work for you? I don t see my model at all as soon as I have the serialize on a Hstore object... but then on a Hash it shows but no field showing ever :(

epinault commented 10 years ago

Actually I removed it and just made the field visible and everything seems to work without any patch.. Now updating the field is a bit tricky as I need to remove the {} around the hash but seems to work partially now.

Saving seems to perform some escaping. Any easy way to prevent it or create my own saving? (maybe like turning the string into a Hash and save it or something alike)

before save {"a"=>"[1, 2, 3]"}

after save on rails_admin {"{\"a\""=>"[1, 2, 3]"}

monkbroc commented 9 years ago

I was able to get support for hstore working by using the Rails 4 store_accessor in my model and listing the fields in the Rails admin config for my model. It's a simple solution.

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
migu0 commented 9 years ago

Awesome, do you want to post it here: http://stackoverflow.com/questions/19235247/railsadmin-hstore-columns-dont-show ?

monkbroc commented 9 years ago

I answer the SO question. I also put my solution in a demo app available on Github.

The demo app includes a module called StoreBoolean that adds support for boolean attributes stored in an hstore field. I'd like some comments on that module.