将鼠标悬停在显示简单表单关联字段的相关文本上

Hover over display related text for simple form association field

我正在使用 Rails 和简单的形式。我有一个 collection,我正在显示一个关联字段。对于 collection 中的每个项目,我想显示悬停在属于该项目的属性的标题上,即 description

这是我的协会:

<%= f.association :user_roles, collection: @roles, as: :check_boxes, label_method: :name, label: false %>

我想在每个角色的描述文本上显示悬停。在我看来,类似以下的事情应该是可行的:

<%= f.association :user_roles, collection: @roles, wrapper_html: {title: UserRole.where(id: this_current_items_id).first.description}, as: :check_boxes, label_method: :name, label: false %>

或:

<%= f.association :user_roles, collection: @roles, wrapper_html: {title: :description}, as: :check_boxes, label_method: :name, label: false %>

这些显然都不起作用,但在我看来,像这样的解决方案应该很容易。估计simple form的小伙伴们都没想过这种情况吧

但是,这可能吗?或者,如何获取当前项目的 ID,以便在悬停时显示该项目的描述?

PS:我需要的是一个简单的表格hover_method!

您可以像这样轻松地向 collection 中的每个项目添加其他属性:

<%= f.association :user_roles, collection: @roles.map { |r| [r.name, r.id, { title: r.description, "data-toggle": "hover" }] }, as: :check_boxes, label: false %>