Ruby on rails CanCan我需要某些角色来访问整个索引,而其他角色只能查看其索引
我正在使用主动管理(包括Desive),我已经使用cancan设置了我的角色。我有一个订购模型。我设置了几个角色。我需要某些角色能够查看所有用户的整个订单索引,然后我需要某些用户只查看他们的订单,而不访问其他用户的订单 在我的订单中,我有这个Ruby on rails CanCan我需要某些角色来访问整个索引,而其他角色只能查看其索引,ruby-on-rails,ruby-on-rails-3,cancan,Ruby On Rails,Ruby On Rails 3,Cancan,我正在使用主动管理(包括Desive),我已经使用cancan设置了我的角色。我有一个订购模型。我设置了几个角色。我需要某些角色能够查看所有用户的整个订单索引,然后我需要某些用户只查看他们的订单,而不访问其他用户的订单 在我的订单中,我有这个 scope_to :current_user, :unless => proc{ current_admin_user.admin? } 我从文档中看到了这个问题,但它只是显示管理员的订单,而不是索引中的所有订单 这是我的能力模型 cla
scope_to :current_user, :unless => proc{ current_admin_user.admin? }
我从文档中看到了这个问题,但它只是显示管理员的订单,而不是索引中的所有订单
这是我的能力模型
class Ability
include CanCan::Ability
def initialize(user)
return if user.nil? #non logged in user can use this.
if user.admin?
can :manage, :all
end
if user.sales?
can [:create, :update] [Order, Customer]
can :read, :all
cannot :destroy, :all
end
if user.production?
can [:create, :update] [Order, Customer]
can :read, :all
cannot :destroy, :all
end
if user.art?
cannot :create, :all
can :read, :all
can :update, Order
cannot :destroy, :all
end
if user.broker?
can [:index, :create, :edit, :update, :read], Order, :id => user.id
can [:index, :create, :edit, :update, :read], Customer, :id => user.id
cannot :destroy, :all
end
if user.shipping?
cannot :create, :all
can :read, :all
can :update, Order
cannot :destroy, :all
end
end
end
我有一种感觉,你在结合规则 文件中较低的能力规则将覆盖以前的能力规则。 - 作为一个调试步骤,请删除除
can:manage,:all
之外的所有内容
如果您的角色相互排斥,则应使用elsif
而不是单独的If
s