为什么专家没有加上像CanCanCan这样的Rolify? [英] Why is Pundit not coupled with Rolify like CanCanCan is?

查看:167
本文介绍了为什么专家没有加上像CanCanCan这样的Rolify?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise,有兴趣使用Pundit,但如果它应该与Rolify集成,或者如果它是独立的,则找不到太多的东西。 CanCanCan可以很好地与Rolify合作,我喜欢角色模型。我错过了一个主要原因,为什么Pundit和Rolify似乎不被一起使用?

I am using Devise and interested in using Pundit but cannot find much on if it should be integrating with Rolify or if it is stand alone. CanCanCan works nicely with Rolify and I like the roles model. Am I missing a major reason why Pundit and Rolify do not seem to be used together a lot?

推荐答案

为什么不一起使用?他们可以很容易地以这样的方式使用

Why don't use them together? They can be easily used in a fashion like this

class OrganisationPolicy
  def initialize(user, organisation)
    @user = user
    @organisation = organisation
  end

  def index?
    @user.has_role? :admin
  end

  def show?
    @user.has_role?(:admin) || @user.organisation == @organisation
  end
end

其实, rolify pundit 没有耦合的东西是好事,而不是设计失败;)

In fact, the thing that rolify and pundit are not coupled is something nice, and not a design failure ;)

这篇关于为什么专家没有加上像CanCanCan这样的Rolify?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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