簡體   English   中英

可以如何在一個控制器中授權收集模型?

[英]Cancan how to authorize collection model in one controller?

我將cancan與rails 4一起使用。我的用戶模型有很多約會,約會有很多回復。 在用戶控制器的show動作中,我要授權所有它們:

@user = User.find params[:id]
authorize! :read, @user

@datings = @user.first_page_datings
authorize! :read, @datings

# How to authorize replies of all the datings here?

問題是如何授權此處所有約會的答復?

與其嘗試授權所有子對象, @dating = @user.datings.accessible_by(current_ability)使用@dating = @user.datings.accessible_by(current_ability)加載允許的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM