Rails 与 Pundit 一起 Rolify
Rails Rolify with Pundit
此 post 中的指南展示了如何使用 rolify 和专家授权。
我正在尝试在我的 Rails 应用程序中弄清楚如何做到这一点。
链接 post 中的答案让我感到困惑的是索引操作检查 :admin
,而显示操作检查 (:admin)
。在某些情况下是否有括号的原因?
Why is Pundit not coupled with Rolify like CanCanCan is?
def index?
@user.has_role? :admin
end
def show?
@user.has_role?(:admin) || @user.organisation == @organisation
end
Ruby 允许省略括号,这更像是一种编码风格。
对于在Ruby中具有关键字状态的方法,我们通常会省略括号。 (puts
、attr_accessor
等)剩下的方法,我们可以用()
您可以在此处了解更多信息:Ruby Style Guide
如果您的意思是括号是因为样式指南使 @user.has_role?(:admin) || @user.organisation == @organisation
比 @user.has_role? :admin || @user.organisation == @organisation
更具可读性,那么有多个代码样式指南。
此 post 中的指南展示了如何使用 rolify 和专家授权。
我正在尝试在我的 Rails 应用程序中弄清楚如何做到这一点。
链接 post 中的答案让我感到困惑的是索引操作检查 :admin
,而显示操作检查 (:admin)
。在某些情况下是否有括号的原因?
Why is Pundit not coupled with Rolify like CanCanCan is?
def index?
@user.has_role? :admin
end
def show?
@user.has_role?(:admin) || @user.organisation == @organisation
end
Ruby 允许省略括号,这更像是一种编码风格。
对于在Ruby中具有关键字状态的方法,我们通常会省略括号。 (puts
、attr_accessor
等)剩下的方法,我们可以用()
您可以在此处了解更多信息:Ruby Style Guide
如果您的意思是括号是因为样式指南使 @user.has_role?(:admin) || @user.organisation == @organisation
比 @user.has_role? :admin || @user.organisation == @organisation
更具可读性,那么有多个代码样式指南。