No commit activity in last 3 years
No release in over 3 years
Field plugin for Administrate to edit JSON array as table of inputs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.7

Runtime

>= 4.2, < 7
 Project Readme

Administrate::Field::JSONArray

A plugin to show and edit JSON objects within Administrate. inspired by Administrate::Field::JSON.

Installation

Add this line to your application's Gemfile:

gem 'administrate-field-json_array'

And then execute:

bundle

If you are using asset pipeline, add the following lines to your manifest.js:

//= link administrate-field-json_array/application.css
//= link administrate-field-json_array/application.js

The manifest file is at app/assets/config by default.

Usage

You shoud pass schema to describe what inputs will be generate. Currently supported :number, :text(textarea) and :string.

ATTRIBUTE_TYPES = {
  # ...
  recipe: Field::JSONArray.with_options(schema: { rank: :number, description: :text }),
}.freeze

How it looks like

Form

Show

Recipes

Store in jsonb

If you want to store your JSON in hash format and not a string add this to your model.

def your_field_name=(value)
  self[:your_field_name] = value.is_a?(String) ? JSON.parse(value) : value
end

Example:

def recipe=(value)
  self[:recipe] = value.is_a?(String) ? JSON.parse(value) : value
end

I18n

You can translate table headers like this

ru:
  activerecord:
    attributes:
      your_model:
      recipe_field:
        add: Добавить строку
        keys:
          rank: Номер
          description: Описание

License

MIT License.