ActiveAdmin:如何处理大型关联 [英] ActiveAdmin: How to handle large associations

查看:109
本文介绍了ActiveAdmin:如何处理大型关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个用于管理可以联系很多人的组织的界面。总人数由几千人组成。



据我所知,AA在这种情况下确实没有一个好的系统。 / p>

到目前为止,我已经在表单框中使用了类似的方法来添加/删除组织中的人员:

  f.has_many:person_organizations,用于:[:person_organizations,f.object.person_organizations.active]做| connection_f | 

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

connection_f.input:person,如下所示: :select,
集合:all_people,
member_label:proc {| d | #{d.firstname}#{d.lastname}
除非connection_f.object.nil?
#仅在已有人员
时显示销毁复选框$否则,已经有动态JS添加/删除新牙医
connection_f.input:_destroy,如::boolean,标签: 删除此连接
结束
结束

此问题是在组织中增加了几个人之后,生成所有选择框所需的时间开始变得很长,因为它必须对每个元素执行几乎相同的工作。见下文( slett denne koblingen的意思是删除此连接)





有人知道减轻这种痛苦的方法吗?



我有一些想法,但是我不太理解如何实现它们:




  • 仅显示文本建立关联后,使用带有人名的字符串代替代替选择框。不过,仍然需要能够删除关联并创建新的关联。

  • 以某种方式缓存生成的选择框。可能会给AA选择正确的值带来一些问题吗?



此外,我知道有一个github问题正在讨论解决方案这种挑战,但如果要实施,似乎还遥不可及: https://github.com/activeadmin/activeadmin/issues/2692#issuecomment-71500513

解决方案

我也遇到了同样的呆滞。您面临的挑战是将创建的已填充选择的数量。我建议使用某种形式的AJAX和Select2 / Chosen组合来自动完成文本框输入。这将大大减少HTML占用空间并加快加载时间。您的管理员也可能会更喜欢用户体验。



https://github.com/activeadmin/activeadmin/issues/1754



https://github.com/mfairburn/activeadmin-select2



Viget Labs有一颗宝石提供了用于处理自动完成关联的替代解决方案。
https://github.com/vigetlabs/active_admin_associations


I'm building an interface for administrating organizations that can have lots of people connected. The total pool of people consists of a few thousand individuals.

To the best of my knowledge, AA doesn't really have a good system for this kind of situation.

So far I've 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's already dynamic JS to add / remove new dentists
    connection_f.input :_destroy, as: :boolean, label: 'Delete this connection'
  end
end

The problem with this is that after adding a few people to an organization, the time it takes to generate all the select boxes begins to be substantial as it has to do pretty much the same work for each element. See beneath ("slett denne koblingen" means "delete this connection")

Does anyone know of a way to alleviate this pain?

I've had a couple of thoughts, but I don't quite understand how I would implement them:

  • Only show a text string with the person's name after the association is set up, in stead of a select box. Need to still be able to delete the association, and create new ones, though.
  • Somehow cache the generated select box. Might give AA some problem with select-ing the correct value?

Also, I'm aware of a github issue discussing a solution to this kind of challenge, but it seems like it's still a way off, if it will ever be implemented: https://github.com/activeadmin/activeadmin/issues/2692#issuecomment-71500513

解决方案

I have encountered the same sluggishness. The challenge you are faced with is the number of populated selects that will get created. I recommend using some form of AJAX and Select2/Chosen combination to "autocomplete" a textbox input. This will greatly reduce the HTML footprint and speed load times. The user experience may be more appreciated by your admins too.

https://github.com/activeadmin/activeadmin/issues/1754

https://github.com/mfairburn/activeadmin-select2

Viget Labs has a gem that provides an alternate solution for handling the autocomplete association. https://github.com/vigetlabs/active_admin_associations

这篇关于ActiveAdmin:如何处理大型关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆