在 rails 上的 Ruby 中提取范围 nil 值
pluck scope nil value in Ruby on rails
嗨,有人能告诉我这里出了什么问题吗?
@organizations_of_user = user.memberships.verified.pluck :organization_id
@organizations_of_user << nil
@permitted_category_ids= Category.where(......, organization_id:@organizations_of_user)
@organizations_of_user 好像有问题。这段代码是我以前的一位同事写的。我不知道这个 << nil 到底在做什么,但不知何故,如果没有这个,代码就会崩溃。但是有了这个,类别范围将只显示 organization_id : nil.
有人知道吗?
非常感谢!
@organizations_of_user是一个数组
@organizations_of_user = user.memberships.verified.pluck(:organization_id) #Extracts organization_ids in an array [1,2,3...]
@organizations_of_user << nil # Adds nil to the array [1,2,3,nil...]
@permitted_category_ids= Category.where(......, organization_id:@organizations_of_user) #Search for Categories with organization_ids inside the array [1,2,3,nil...]. (nil extracts Categories without an organization_id)
嗨,有人能告诉我这里出了什么问题吗?
@organizations_of_user = user.memberships.verified.pluck :organization_id
@organizations_of_user << nil
@permitted_category_ids= Category.where(......, organization_id:@organizations_of_user)
@organizations_of_user 好像有问题。这段代码是我以前的一位同事写的。我不知道这个 << nil 到底在做什么,但不知何故,如果没有这个,代码就会崩溃。但是有了这个,类别范围将只显示 organization_id : nil.
有人知道吗?
非常感谢!
@organizations_of_user是一个数组
@organizations_of_user = user.memberships.verified.pluck(:organization_id) #Extracts organization_ids in an array [1,2,3...]
@organizations_of_user << nil # Adds nil to the array [1,2,3,nil...]
@permitted_category_ids= Category.where(......, organization_id:@organizations_of_user) #Search for Categories with organization_ids inside the array [1,2,3,nil...]. (nil extracts Categories without an organization_id)