这是我的 Ability.rb 文件:
class Ability
include CanCan::Ability
def initialize(user)
user.permissions.each do |permission|
can permission.action.to_sym,
permission.thing_type.constantize {|thing| thing.nil? || permission.thing.nil? || permission.thing_id == thing.id}
end
end
end
事物是多态关联。我试图了解如何将块传递给 can 工作。我在整个 wiki 中搜索了 CanCan,但找不到解释。