ActiveAdmin form for nested jsonb field

Viewed 129

I am building a new/edit form for an ActiveRecord model in ActiveAdmin. One of the attributes of that model is a jsonb attribute. Its value is expected to be a Hash whose values are themselves Hashes:

{
  'foo' => {
    'a' => 1,
    'b' => 2
  },
  'bar' => {
    'c' => 3,
    'd' => 4
  }
}

The MVP that I'm going for is to generate a form that looks like this:

Foo

a __________________

b __________________

Bar

c __________________

d __________________

So essentially, I only want to ask the user to input values for each of the inner Hashes. I've been having some trouble doing this with ActiveAdmin. This is my best attempt to render the above form, but it only renders the "Bar" section. :jsonb_field is the name of the jsonb attribute on the model.

      f.inputs name: 'JSONB', for: :jsonb_field do |jsb|
        jsb.inputs name: 'Foo', for: 'foo' do |x|
          x.input :a
          x.input :b
        end
        jsb.inputs name: 'Bar', for: 'bar' do |y|
          y.input :c
          y.input :d
        end
      end

I feel like there's a proper way to do this but my research has come up empty. Can anyone help me figure out how to make this happen? Thank you!

0 Answers
Related