简体   繁体   English

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

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

I am using cancan with rails 4. My user model has many datings and a dating has many reply. 我将cancan与rails 4一起使用。我的用户模型有很多约会,约会有很多回复。 In the user controller's show action, I want to authorize all of them: 在用户控制器的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?

Question is 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