2016-02-19 58 views
0

我們如何在創建和更新記錄時使用rails中的權威人員來授權關聯。權威人士的記錄協會

例如,如果我們正在更新屬於postcomment記錄,我們需要確保用戶有權訪問該帖子,否則這是安全漏洞。

回答

1

裏面的create動作,你可以這樣做:

def create 
    authorize @comment.post # this checks the authorization of Post 
    authorize @comment # and then for comment 
    #.. then code to create the comment 
end