康康无障碍版 [英] Cancan accessible_by
问题描述
当我这样做时到底发生了什么?
What exactly is happening when I do:
@patient.course_enrollments.accessible_by(current_ability)
发生的事情是我得到了course_enrollments,其中 course.client_id = user.client.id
,我只是不明白 accessible_by
的工作原理。
What seems to happen is I get course_enrollments where course.client_id = user.client.id
, I just don't understand how accessible_by
works.
# ability.rb
can :manage, CourseEnrollment, :course => {:client_id => user.client.id}
推荐答案
> accessible_by
为您提供一个范围,该范围仅包含在 current_ability
情况下您可以访问的记录。既然您说过 CourseEnrollment
的:manage
能力是由当前用户拥有的课程过滤的,所以 accessible_by
调用将添加相同的限制,以便返回的课程注册都将由当前用户访问。
accessible_by
gives you a scope that includes only those records which you'd be able to access given the current_ability
. Since you stated that the :manage
ability on CourseEnrollment
is filtered by courses owned by the current user, the accessible_by
call will add in that same restriction so that the course enrollments returned will all be "accessible by" the current user.
这篇关于康康无障碍版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!