1

我已经尝试了大约 2 个小时来完成这项工作,但我根本做不到。我的问题找到的答案似乎都不起作用。

我有一个 has_many :通过这样的关联:

class Request < ActiveRecord::Base

  has_many :dialogs
  has_many :companies, :through => :dialogs

class Dialog < ActiveRecord::Base
  belongs_to :request
  belongs_to :company

在我的能力.rb 文件中,我试图让公司只能看到它的请求(即查看 current_user id 是否在特定请求的对话框中)。

我尝试了很多方法,但没有成功。我必须以某种方式接近,但无法弄清楚:

can [:show, :destroy], Request, :dialogs => {:company_id => user.rolable.id}

任何人都可以帮忙吗?

4

1 回答 1

1

您始终可以使用块定义能力:

can [:show, :destroy], Request do |request|    
  request.dialogs.where(company_id: user.rolable.id).any?
end

不确定我是否确定了您正在寻找的条件,但您得到了图片。

于 2013-04-08T06:47:43.790 回答