康康舞新动作
我向我的 Restful 资源添加了新操作,如何使用 cancan 授权它。
页面控制器:
load_and_authorize_resource
def index
end
def show
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
def mynewaction
end
能力模型:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :create, Page
can :mynewmethod, Page #does it work?
end
I added new action to my restful resources how can I authorize it with cancan.
Pages controller:
load_and_authorize_resource
def index
end
def show
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
def mynewaction
end
Ability model:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :create, Page
can :mynewmethod, Page #does it work?
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我相信它适用于 CRUD 方法以外的其他方法,尽管这只是查看一些文档,请查看 此处 和 ryanb 的实际文档在这里。
您应该特别查看第一个链接,该链接表示
load_and_authorize_resource
将应用于控制器中的所有方法,甚至是通常的 CRUD 方法之外的方法。我认为最简单的方法就是测试一下,当你启动它时它是否正确授权?没有什么比尝试更好的了。
Yes I believe it works for things other than the CRUD methods, although this is just from looking at some of the documentation, check out here and the actual documentation by ryanb here.
You should especially look at that first link that says that the
load_and_authorize_resource
will apply to all methods in the controller, even ones other than the usual CRUD ones.I think the easiest way is just to test it out, does it authorize correctly when you fire it up? Nothing better than to try.