ActiveAdmin: how to handle large associations

I am creating an interface for administering organizations that can connect a lot of people. The total pool of people consists of several thousand people.

As far as I know, AA does not have a really good system for this kind of situation.

So far I have used something like this in the form block to add / remove people from the organization:

f.has_many :person_organizations, for: [:person_organizations, f.object.person_organizations.active] do |connection_f|

  all_people = Person.select([:id, :firstname, :lastname]).order(:firstname, :lastname)

  connection_f.input :person, as: :select,
                              collection: all_people,
                              member_label: proc { |d| "#{d.firstname} #{d.lastname}"
  unless connection_f.object.nil?
    # Show the destroy checkbox only if it is an existing person
    # else, there already dynamic JS to add / remove new dentists
    connection_f.input :_destroy, as: :boolean, label: 'Delete this connection'
  end
end

The problem is that after adding a few people to the organization, the time taken to create all the selection boxes becomes significant because it should do almost the same job for each element. See below ("slett denne koblingen" means "delete this connection")

Organization with some people added

Does anyone know how to alleviate this pain?

I had a few thoughts, but I don’t quite understand how to implement them:

  • , ​​, . - .
  • - . AA ?

, github, , , , - : https://github.com/activeadmin/activeadmin/issues/2692#issuecomment-71500513

+4
2

, , .

, select2, . , ( select2 ajax ), "" . , , , .

, : "has_many", , :

f.inputs 'Personer' do
      f.has_many :person_organizations, for: [:person_organizations, f.object.person_organizations.active], new_record: false do |connection_f|
        if connection_f.object.person.present?
          li connection_f.object.person.name
          li link_to 'destroy', { controller: :person_organizations, action: :destroy, id: connection_f.object.id }, method: :delete, data: { confirm: 'Are you sure?' }
          li link_to 'edit', edit_admin_person_organization_path(connection_f.object)
        end
      end
    end

    li link_to 'Add new person-organization connection', new_admin_person_organization_path(id: f.object.id)

ActiveAdmin.register PersonOrganization .

controller do
  def update
    update! do |format|
      format.html { redirect_to edit_admin_medical_practice_path(resource.organization) } if resource.valid?
    end
  end
end

AA, .

0

All Articles