我很难理解这句话的逻辑:
if (current_user.has_role? :admin, current_user.active_org)
has_role?
正在查看两个参数并返回一个布尔值。这大概是CanCan
吧?如果是这样,它会说“当前用户是当前用户的活动 'org' 的管理员吗?”
Ability
如果您想要更准确的答案,请发布您的课程。
基本上测试 admin 或 current_user.active_org 是否有效,基于是否设置了 has_role ......与:
if (current_user.has_role)
if (admin)
stuff...
end
else
if (current_user.active_org)
same stuff...
end
end
但只是更压缩。