你可以在CanCan中重写大多数这些块,使它们复杂得多。
can :edit, DinnerClub, cancelled: false, chef_id: user.id # open or close a dinner club can [:open, :close], DinnerClub, passed: false, chef_id: user.id # take the dinner club from another use if the dinner club is canceled can [:take], DinnerClub, cancelled: true, kitchen_id: user.kitched_id, passed: false can [:take], DinnerClub, cancelled: true, kitchen: { open_registrations: true }, passed: false cannnot [:take], DinnerClub, chef_id: user.id
这是假设的 cancelled? 和 passed? 方法是从DinnerClub模型的布尔属性派生而来的 is_chef? 方法检查chef_id。但它说明了这个想法。
cancelled?
passed?
is_chef?
CanCan主要用于根据资源定义能力,所以我会坚持下去。