CanCan,索引和显示之间有什么不同?

发布于 2024-12-01 20:58:43 字数 209 浏览 0 评论 0原文

我在能力.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2024-12-08 20:58:43

正如此处 所示: index:show:read 的别名,这意味着它们是同义词。

当您说 can :index, Thread 时,意味着用户将能够读取任何内容。
当您稍后定义第二条规则时 can :show, Thread {|t| 1 == 2},CanCan 对连续规则的查询是析取的,即 result =rule1 或rule2。要通过差异计算结果 result = Rule1 - Rule2,请使用 cannot 作为第二条规则:

cannot :show, Thread {|t| 1 == 2}

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 is result = rule1 or rule2. To have the result computed via difference result = rule1 - rule2 use cannot for the 2nd rule:

cannot :show, Thread {|t| 1 == 2}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文