获取特定Rolify角色的资源

时间:2016-12-13 04:34:23

标签: ruby-on-rails authorization rolify

鉴于我有一个如此定义的角色:

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

我可以确定用户是否具有

的任何论坛的管理员角色
User.first.has_role?(:admin, :any)

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

1 个答案:

答案 0 :(得分:0)

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

相关问题