[英]Checking abilities in CanCan on a namespaced controller
Given the following example from the CanCan wiki, 给定CanCan Wiki中的以下示例,
https://github.com/ryanb/cancan/wiki/Admin-Namespace https://github.com/ryanb/cancan/wiki/Admin-命名空间
How would I do a can? 我该怎么做一个罐头? check within a view for the namespaced article controller.
在视图中检查命名空间文章控制器。
For the purpose of this, imagine the ability.rb file states the current user.role is able to view an article, and the admin_ability.rb states the user can create an article 出于此目的,想象一下ability.rb文件指出当前用户。role能够查看文章,而admin_ability.rb指出用户可以创建文章。
<% if can? :read, Articles %>
I can view an article
<% end %>
<% if can? :create, Articles %>
I can create an article
<% end %>
I don't know how to get the latter to work. 我不知道如何使后者工作。 It would be neat if I could specify the namespace on it perhaps such as
如果可以在上面指定名称空间,那将是一件很整洁的事情
<% if admin::can? :create, Articles %>
But I am not sure what the syntax would be if that were possible. 但是我不确定如果可能的话语法会怎样。
I don't think Marc's suggestion will work. 我认为马克的建议行不通。 Checkout this wiki from Ryan.
从Ryan检阅此Wiki。 https://github.com/ryanb/cancan/wiki/Admin-Namespace
https://github.com/ryanb/cancan/wiki/Admin-命名空间
你有没有尝试过:
<% if can? :create, Admin::Articles %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.