【发布时间】:2013-08-24 17:19:49
【问题描述】:
用户 has_many 合同作为买方 用户作为卖方拥有_many 个合同
我知道我可以使用 CanCan 将用户限制为他们拥有的东西。但在这种情况下,我有一份同时包含买方和卖方的合同。我希望用户能够查看/阅读他们是买方或卖方的所有合同。
我尝试设置一个 Scope 并将其与 CanCan 一起使用,但这似乎不起作用。
我这样设置我的能力...
can :read, Contract.parties(user.id)
我的范围被定义为...
scope :parties, lambda { |user_id| where("seller_id = ? OR buyer_id = ?", user_id, user_id) }
我也尝试过以不同的方式设置能力...
can :read, Contract, buyer_id: user.id
can :read, Contract, seller_id: user.id
但是上面好像有冲突,会报错
【问题讨论】:
标签: permissions ruby-on-rails-4 cancan