O
O
Ord EO2019-08-23 16:01:12
Ruby on Rails
Ord EO, 2019-08-23 16:01:12

How do I set the default value in an Active Admin form?

There is a form in active admin, it has a certain select of 4 items, I need to set one of these items by default, how can I do this?

def dropdown_select_collection_by(scope:)
      DropdownOption.send(scope).pluck(:label, :id)
    end


f.input(:work_status,
              as: :select,
              collection:  dropdown_select_collection_by(scope: :work_status))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alekseiev, 2019-08-23
@OrdeO

f.input(:work_status,
              as: :select,
              collection:  dropdown_select_collection_by(scope: :work_status)),
              selected: dropdown_select_collection_by(scope: :work_status)&.first || 'Default'

For example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question