当使用专家时我明白我可以针对模型授权当前用户。简单。
我有一个场景,我希望根据模型授权用户并在第二个模型中确认标准,但Pundit只允许单个模型。
即
学生为自己的课程撰写文章,并对文章发表评论。
Class has many students M:M
Student has many classes M:M
Class has many articles 1:M
Article has many comments 1:M
Student has many articles 1:M
Student has many comments 1:M
在文章控制器中,我需要授权:
Create action: Student is a member of the class
Destroy action: Student is member of class and is owner of article
在评论控制器中,我需要授权:
Create action: Student is a member of class and article is not closed to comments
Destroy action: Student is member of class and is owner of article
我希望在这里可以看到创作和销毁文章时的情况。评论我需要批准两个模型。始终是class_memberships加上文章或评论。
这可以在Pundit中完成,因为我读到它只能授权用户使用一个模型。