2011-10-17 38 views
2

进出口使用惨惨load_and_authorize_resource helper方法用于获取资源和产生的授权,但我有这样惨惨宝石与嵌套的资源和:find_by

load_and_authorize_resource :company 
load_and_authorize_resource :accountings, :through => :company, :class => 'Departments::Accounting' 

一个嵌套的资源,但我需要 @accountings通过其他属性找到而该Departmets ::会计ID,并给一个值,属性,例如

@accountings = @company.find_by_period_id(@period.id)

回答

1

您可以有两个额外的选项做到这一点:

load_and_authorize_resource :accountings, 
    :through => :company, :class => 'Departments::Accounting', 
    :find_by => :attr, # :period_id in your example 
    :id_param => :something # this searches the params hash for 
          # params[:something], and sends that 
          # value to .find_by_attr 

检查代码load_and_authorize_resourcehere