获取特定 Rolify 角色的资源

Get the resource for a specific Rolify role

假设我有一个这样定义的角色:

User.first.add_role(:admin, Forum.first)

我可以确定用户是否具有任何论坛的管理员角色

User.first.has_role?(:admin, :any)

有没有办法获取 this 指向的实际资源?例如,在这种情况下,如果用户有多个 :admin 角色,我会取回 Forum.first,或者可能是一组资源。

Forum.with_role(:admin, current_user)
# => [ list of Forum instances that have role "admin" bound to them and belong to current_user roles ]

参见resource roles querying