Instructions
Opened this issue · 2 comments
I’ve got a model attribute whose type is ‘json’ that I’d like to edit within RailsAdmin’s interface. Based on the name of your gem it seems like a good fit - but I don’t know how to use it ? I did try installing it hoping that through the ‘magic of rails’ (perhaps via introspection) it would just work - but it did not.
How does one use this gem ?
Thanks
Dave
I'm sorry, I didn't got the time to write a proper readme and release. I'm also not sure if this package runs properly on current releases of ruby, rails and rails-admin. Please advice! I do use it in 2 production apps without any problems though :)
Some notes to get you on the way:
- You can give the column where you're storing json a type of
text
instead ofjson
. I don't have any experience with thejson
-type, buttext
will work fine. - You'd have to do the parsing (when you're rendering a page in the frontend) yourself, this is only a interface for RailsAdmin to structure a json-blob.
- In
initializers/rails_admin.rb
, add the following config for your column (components_json
in my case)
field :components_json, :json_editor do
label 'Components'
help ''
schema do
model 'image' do |c|
c.label 'Image'
c.field :image, :picker do |f|
f.picker model: Image, preview_image_field: :cdn_url
end
c.field :caption, :string
c.field :size, :enum do |f|
f.enum ['large', 'small']
end
c.field :modal_enabled, :boolean do |f|
f.label 'Fullscreen'
end
end
model 'quote' do |c|
c.field :body, :text
c.field :cite, :string
end
model 'image-text-list' do |c|
c.label 'List of images and text'
c.field :items, :list do |f|
f.list ['image-text-list-item']
end
end
model 'inset' do |c|
c.label 'Inset'
c.field :body, :text
c.field :components, :list do |f|
f.list ['image-text-list'], max_length:1
end
end
model 'video' do |c|
c.label 'Video'
c.field :vimeo_url, :string
end
# and so on...
end
end
I think those are the options and types you have. I'll be happy to assist further on (and hopefully make a proper release of this any time soon..)
You could also take a look at lib/rails_admin_json_editor.rb and app/views/rails_admin_json_editor/main/component_fields for further options.