我有这段代码定义了 CanCan 的用户权限,但我不明白块内的条件是什么?
class Ability
include CanCan::Ability
def initialize(user)
user.permissions.each do |permission|
can permission.action.to_sym,
permission.thing_type.constantize do |thing|
thing.nil? || permission.thing_id.nil? || permission.thing_id == thing.id
end
end
end
end
所以,这行代码困扰着我:
permission.thing_type.constantize do |thing|
thing.nil? || permission.thing_id.nil? || permission.thing_id == thing.id
end
我知道该块用于定义复杂的条件,我想它 permission.thing_id == thing.id
是这样的,因此仅授予选定对象的权限,但我看不到 . thing.nil? || permission.thing_id.nil?
那是什么目的?