0
votes

I've a hard time with ActiveAdmin and their DSL. I'm using it to build my admin and at some point in a form I need to have a text_field_tag; I mean some fields which aren't related to the model I'm manipulating in the form which will be sent through with the model related data.

A custom text field basically. Nothing too crazy.

So I've built this

panel 'Send payment authorization' do
  active_admin_form_for EventPaymentAuthorization.new, url: { action: :send_event_payment_authorization } do |f|
    f.inputs do
      f.input :body, as: :text

      f.text_field_tag :line_items_label
      f.text_field_tag :line_items_amount

      f.input :fees_in_cents, as: :select, collection: [:free, :automatic], prompt: true, selected: :automatic
    end
    f.actions do
      f.action :submit, label: 'Create payment authorization'
    end
  end
end

The f.text_field_tag get simply ignored by ActiveAdmin. Why is that? It doesn't raise any error, but it doesn't show either.

The reason I need custom unrelated inputs is because line_items in my example is a JSONB with values such as [{amount: 0.0, label: 'Hello'}] and I don't believe it can be processed through Formtastic or ActiveAdmin natively. It's also always good to be able to create custom inputs when sending data.

1
Try f.text_field instead. - chumakoff

1 Answers

0
votes

Working with JSON in ActiveAdmin is a bit tricky, it largely depends on your needs. The quickest way to get going is to use the activeadmin_json_editor gem. I also wrote a blog entry on working with JSON in ActiveAdmin with more detail and another approach, which may better suit your needs, as it appears you are not just working with arbitrary data into your JSON field.