简体   繁体   中英

ActiveAdmin Resource Form: Replacing belongs_to Select Input with Alternative format

Is there a quick and easy method/library to replace an ActiveAdmin resource's belongs_to association (Formtastic) input that meets these requirements?

  • It does not load every record from the table onto the page. That's the problem with the default select dropdown. If my Users table has 100k records, it has to render every record's :name and :id into the dropdown.
  • It autocompletes or provides some AJAX-like feedback that I'm selecting an associated record that actually exists. A simple textbox where I must know the ID of the associated record is not sufficient.

I would hope that the resulting code would look like:

# in app/models/my_resource.rb
class MyResource
  belongs_to :user
end

# in app/admin/my_resource.rb
form do |f|
  f.inputs 'Details' do
    f.input :user, as: :something_convenient, plus_optional: :parameters_if_needed
  end
  f.actions
end

The thing you are looking for is chosen-rails gem.

Some time ago I've answered few questions on the topic, so not to repeat stuff please see them for more details:

Answer 1

Answer 2

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