Martin Verdejo
Martin Verdejo

Reputation: 1369

how to add an active admin field for a postgres jsonb field

While this works with the jsonb field:

step.title['en'] = 'Lorem'
step.save
step.title
=> {"en"=>"Lorem"}

The following doesn't

form do |f|
  f.inputs name: 'Title', for: :title do |t|
    t.input :en, input_html: { value: f.object.title['en'] } if f.object.present?
    end
  end
end

Re asking based on this question cos answer doesn't seem to work for my case: Unable to find input class for json - handling JSON type in Active Admin

Upvotes: 3

Views: 2965

Answers (1)

rylanb
rylanb

Reputation: 614

I figured it out using the link from your original question.

This is what mine looks like:

admin/client.rb

permit_params :name, settings: [ Client.storext_definitions.keys ]

f.inputs name: "Client Settings", for: :settings do |s|
  s.input :status_for_map, as: :select, collection: options_for_select( Order.statuses.map{ |status, id| [status.humanize, status] }, client.settings['status_for_map'])
  s.input :time_zone, input_html: { value: "#{client.settings['time_zone']}" }
end

Hopefully that helps you or anyone following up.

Upvotes: 2

Related Questions