康康舞:“管理”和“管理”之间的区别以及“读取、创建、更新和销毁”的组合?
在尝试调试 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,CanCan 将
:read
、:create
等映射到相关的控制器操作,例如:但是,当然,您不仅限于在控制器中执行这些操作,最终控制器操作可以有任何名称。出于同样的原因,您在 CanCan 中并不局限于只有
:read, :create, :update, :detroy
。您可以为任何控制器操作指定任何符号的别名。假设您的控制器上有一个名为do_cool_things
的操作,然后您可以将任何符号别名为该操作以供 CanCan 使用,例如:然后您就可以执行以下操作:
这意味着当前用户可以访问
NeighborhoodsController
的:do_cool_things
方法。但是,如果您使用了:manage
,则无需定义此单独的操作,因为:manage
是一个包罗万象的操作。因此,如果您这样做:当前用户仍然可以访问控制器的
:do_cool_things
方法。因此,
:manage
可以让您执行任何操作,但:read、:create、:update 和 :destroy
只是您可以定义的无数 CanCan 操作中的 4 个,映射到您选择的任何控制器操作。By default CanCan maps
:read
,:create
etc. to the relevant controller actions e.g.: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 calleddo_cool_things
, you can then alias any symbol to that action to be used by CanCan e.g.:You would then be able to do this:
Which means the current user would have access to the
:do_cool_things
method of theNeighborhoodsController
. 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: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.您可以定义自定义操作(当您为给定模型定义用户的能力时,您不限于 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.