2011-10-17 39 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