【发布时间】:2011-07-26 05:49:02
【问题描述】:
我有以下几点:
-
has_and_belongs_to_many餐厅的用户模型,反之亦然。 - 餐厅模特
that has_and_belongs_to_many用餐,反之亦然。
在我的ability.rb 文件中,我想指定用户只能管理他“has_and_belongs_to”的餐厅(即user.restaurants 中的餐厅)的餐点。
我现在有这个:
class Ability
include CanCan::Ability
def initialize(user)
# a user can only manage meals of restaurants he has access to
can :manage, Meal do |meal|
meal.restaurant_ids & user.restaurant_ids #...this doesn't work...
end
end
end
最好的方法是什么?
我咨询了https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks,但我还是不知道。
【问题讨论】:
标签: ruby-on-rails has-and-belongs-to-many cancan