2011-06-28 89 views
0

我有資源嵌套資源慘慘

resources :companies do 
    resources :stands 
end 

,我想控制公司展臺的訪問。 In Ability class i write

can :manage, :all if user.has_role? Role.super_admin 

    can :manage, Company do |c| 
     user.has_role? Role.company_admin, c 
    end 

我如何控制公司看臺的訪問?例如,公司管理員可以只搜索他的公司看臺。謝謝

回答

0

坎康將幫助我們設置操作的權限。它不會給你拿基礎上,許可記錄設置的Ability.rb

例:

網址: /站/搜索

def search 
    authorize! :search, Stand 
    current_user.company.search_stands('some-query') # This will get the stands only for the current-users's company 
end 

Ability.rb 可以:搜索,站 用戶.has_role? Role.company_admin 結束

分例: /公司/ 1 /站/搜索

def search 
    @company = Company.find(params[:company_id]) 
    authorize! :search_stands, @company 
    @stands = @company.search_stands('some-query') 
end 

Ability.rb

can :search_stands, Company do |c| 
    user.has_role? Role.company_admin # Only admin has the permission to search stands. 
end 
+0

https://github.com/ryanb/cancan/wiki /嵌套資源 這是怎麼回事,它可以幫助我嗎? – maxfry