Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Instructions #2

Open
dekhaus opened this issue Jan 26, 2016 · 2 comments
Open

Instructions #2

dekhaus opened this issue Jan 26, 2016 · 2 comments

Comments

@dekhaus
Copy link

dekhaus commented Jan 26, 2016

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

@Jpunt
Copy link
Owner

Jpunt commented Jan 26, 2016

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 of json. I don't have any experience with the json-type, but text 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..)

@Jpunt
Copy link
Owner

Jpunt commented Jan 26, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants