我有一个帐户模型,它“有许多”用户,也有“许多”米。Meter对象有一个account_id列,因此很容易在Cancancan中定义这样的功能:
if user
can :crud, Meter, :account_id => user.account_id
end然而,一个米也“有许多”参数。我想做一个类似的能力定义,只允许CRUD访问,如果参数属于一个表,它属于同一个帐户的用户。
由于参数模型只有一个meter_id列(而不是一个account_id列),我不确定实现这个额外嵌套级别的最佳方法?
编辑
为不清楚而道歉。
我的模型如下:
Account > User (account_id)
> Meter (account_id) > Parameter (meter_id)所以我可以检查user.account_id = meter.account_id,但是我不知道如何检查参数。
编辑2
除了马特的回答之外,这只是一个简单的例子:
load_and_authorize_resource :meter
load_and_authorize_resource through: :meter在参数模型中。
发布于 2015-06-02 15:30:25
if user
can :crud, Parameter, meter: { account_id: user.account_id }
endhttps://stackoverflow.com/questions/30600199
复制相似问题