康康舞accessible_by
当我这样做时到底发生了什么:
@patient.course_enrollments.accessible_by(current_ability)
似乎发生的是我得到了 course_enrollments,其中 course.client_id = user.client.id
,我只是不明白 accessible_by
是如何工作的。
# ability.rb
can :manage, CourseEnrollment, :course => {:client_id => user.client.id}
What exactly is happening when I do:
@patient.course_enrollments.accessible_by(current_ability)
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}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 thecurrent_ability
. Since you stated that the:manage
ability onCourseEnrollment
is filtered by courses owned by the current user, theaccessible_by
call will add in that same restriction so that the course enrollments returned will all be "accessible by" the current user.