CanCan,索引和显示之间有什么不同?
我在能力.rb 中有以下内容,
can :index, Thread
can :show, Thread do |thread|
1 == 2
end
我将显示结果硬编码为 false 以测试失败。令人震惊的是,演出从未失败。线程索引和线程都显示返回,而不会导致 CanCan 访问被拒绝。这是怎么回事?建议?谢谢
I have the following in ability.rb
can :index, Thread
can :show, Thread do |thread|
1 == 2
end
I hard coded show to result as false to test a fail. Shockingly, show never fails. Both Thread index and Thread show both return without resulting in a CanCan access denied. What's going on with that? Suggestions? Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如此处
所示: index
和:show
是:read
的别名,这意味着它们是同义词。当您说
can :index, Thread
时,意味着用户将能够读取任何内容。当您稍后定义第二条规则时
can :show, Thread {|t| 1 == 2}
,CanCan 对连续规则的查询是析取的,即result =rule1 或rule2
。要通过差异计算结果result = Rule1 - Rule2
,请使用cannot
作为第二条规则:As can be seen here
:index
and:show
are aliases of:read
, that means they are synonyms.When you say
can :index, Thread
that means the user will be able to read anything.When you later define second rule
can :show, Thread {|t| 1 == 2}
, the CanCan query for successive rules is disjunctive, that isresult = rule1 or rule2
. To have the result computed via differenceresult = rule1 - rule2
usecannot
for the 2nd rule: