[英]RoR: CanCanCan authorize only user created items
此代碼有什么問題? 普通用戶仍然只能看到自己的所有相關信息。
我的查看代碼:
<% if can? :read, Relato %>
<td><%= relato.id %></td>
<td><%= relato.cliente.name %></td>
<td><%= relato.projeto.name %></td>
<td><%= relato.local.logra %></td>
<td><%= relato.time %></td>
<td><%= relato.comment %></td>
<% end %>
我的Ability
班:
can :manage, :all if user.role == "admin"
if user.role == "normal"
can :read, Relato , :user_id => user.id
can :manage, Relato, :user_id => user.id
end
您需要為特定實例授權用戶:
<%= if can? :read, relato %>
當您嘗試如上所述為整個類授權用戶時,CanCanCan會忽略“能力”中定義的任何條件,因為它無法確定整個Relato
模型的user_id
字段。 它只能對單個relato
實例執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.