简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM