2014-09-06 38 views
0

我正在使用CanCanCan,我試圖禁止用戶訪問其他用戶的畫廊,但無法找到在Ability類中執行此操作的正確方法。在Rails中的兒童模型上使用Cancan授權

用戶HAS_ONE檔案

檔案HAS_ONE畫廊

def user_abilities(user) 
    can :read, Profile 

    can [:edit, :update], Profile, user_id: user.id 
    can [:edit, :update], Gallery, user_id: user.id # also tried gallery: { user_id: user.id }, profile_id: user.profile.id and so on 

    end 

在我看來,我已(失敗)嘗試了所有的意見,我能找到StackOverflow上的。

+0

是什麼這個問題'可以[:編輯:更新],畫廊,PROFILE_ID:user.profile.id'? – Mandeep 2014-09-06 19:40:48

回答

0

OK解決了這個問題後,我仔細閱讀文檔

class GalleriesController < ApplicationController 

    load_and_authorize_resource :profile 
    load_and_authorize_resource :gallery, through: :profile, singleton: true