简体   繁体   English

CanCan能力和封锁的问题

[英]Issue with CanCan ability and block

I have problem with cancan. 我对康康舞有疑问。 I add role in ability.rb 我在capability.rb中添加角色

if user
 can :manage, Account do
  (some code which return boolean value). For example: user.verify?
 end
end

and on my view for button I add verify 并在我的按钮视图上添加验证

if can? 如果能? :index, Article :索引,文章

I see my button all the time irrespective of the result block true or false. 无论结果块为真还是假,我一直都在查看我的按钮。 Thank you for help 谢谢你的帮助

If an ability for a class is defined using a block, the block will be ignored when checking on the class. 如果使用块定义了一个类别的能力,则在检查该类时,该块将被忽略。 You'll need to check on an instance of the class, like so: 您需要检查该类的实例,如下所示:

if can? :index, Article.new

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM