Search code examples
ruby-on-railsrubyactiveadminformtastic

How to customize the form in the edit view of a resource in Rails active_admin?


I have a form in the edit view in my rails app and this edit view is that of a resource in the active_admin directory.

I know active admin used formtastic I cannot find a view template for the edit view.

If I want to change the form so that a field has a drop down menu instead of a type-in field. Where and how can I set this?

Thanks


Solution

  • Example:

    Inside of app/admin/model_name.rb

    ActiveAdmin.register ModelName do
      form do |f|
        f.inputs "ModelName" do
          f.input :title, :required => true
          f.input :name
          #
          # ... other inputs ...
          #
          f.input :foo, :as => :select, :collection => ModelName.all.map{ |x| [x.title, x.id] }
        end
        f.buttons
      end
    end
    

    How it's done:

    :as => :select
    

    creates a select input

    :collection => [ [text, value], [text, value] ...]
    

    represent the options in the select input.