康康舞:“管理”和“管理”之间的区别以及“读取、创建、更新和销毁”的组合?

发布于 2024-11-29 09:33:46 字数 289 浏览 0 评论 0原文

在尝试调试 cancan 的使用时,我发现如果使用以下内容,我可以通过 accessdenied 消息:

  can :manage, Model

当我将其更改为以下内容时,我被拒绝访问:

  can :read, Model
  can :create, Model
  can :update, Model
  can :destroy, Model

管理包括读取、创建、更新和销毁的组合做什么不是?

谢谢。

In trying to debug use of cancan i found that if use the following i can get past the accessdenied message:

  can :manage, Model

When i changed it to the following I am denied access:

  can :read, Model
  can :create, Model
  can :update, Model
  can :destroy, Model

What does manage include that the combination of read, create, update and destroy do not?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

如梦初醒的夏天 2024-12-06 09:33:46

默认情况下,CanCan 将 :read:create 等映射到相关的控制器操作,例如:

def default_alias_actions
  {
    :read => [:index, :show],
    :create => [:new],
    :update => [:edit],
  }
end

但是,当然,您不仅限于在控制器中执行这些操作,最终控制器操作可以有任何名称。出于同样的原因,您在 CanCan 中并不局限于只有 :read, :create, :update, :detroy。您可以为任何控制器操作指定任何符号的别名。假设您的控制器上有一个名为 do_cool_things 的操作,然后您可以将任何符号别名为该操作以供 CanCan 使用,例如:

alias_action :do_cool_things, :to => :coolify

然后您就可以执行以下操作:

can :coolify, Neighborhood

这意味着当前用户可以访问 NeighborhoodsController:do_cool_things 方法。但是,如果您使用了 :manage,则无需定义此单独的操作,因为 :manage 是一个包罗万象的操作。因此,如果您这样做:

can :manage, Neighborhood

当前用户仍然可以访问控制器的 :do_cool_things 方法。

因此,:manage 可以让您执行任何操作,但 :read、:create、:update 和 :destroy 只是您可以定义的无数 CanCan 操作中的 4 个,映射到您选择的任何控制器操作。

By default CanCan maps :read, :create etc. to the relevant controller actions e.g.:

def default_alias_actions
  {
    :read => [:index, :show],
    :create => [:new],
    :update => [:edit],
  }
end

But, of course you're not restricted to having just those actions in your controller, ultimately a controller action can have any name. By the same token you're not restricted to having just :read, :create, :update, :detroy in CanCan. You can alias any symbol to any controller action. Let us say you have an action on your controller called do_cool_things, you can then alias any symbol to that action to be used by CanCan e.g.:

alias_action :do_cool_things, :to => :coolify

You would then be able to do this:

can :coolify, Neighborhood

Which means the current user would have access to the :do_cool_things method of the NeighborhoodsController. However if you had used :manage you wouldn't need to define this separate action since :manage is a catch-all. So if you had done:

can :manage, Neighborhood

The current user would still have had access to the :do_cool_things method of the controller.

So, :manage lets you do anything, but :read, :create, :update and :destroy are only 4 of an infinite number of CanCan actions that you can define and map to any controller action you choose.

遗弃M 2024-12-06 09:33:46

您可以定义自定义操作(当您为给定模型定义用户的能力时,您不限于 7 个 RESTful 操作(创建、更新、销毁等),您可以创建自己的操作。)如果您已管理所有操作,您也可以访问这些自定义操作。

You can define custom actions (When you define a user's abilities for a given model, you are not restricted to the 7 RESTful actions (create, update, destroy, etc.), you can create your own.) If you have manage all, you wold be able to access those custom actions too.

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