嗨,有人可以告诉我这里出了什么问题吗?
@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有一些问题。这段代码是我以前的同事写的。我不知道究竟是什么&lt;&lt; nil正在做,但不知怎的,没有这个,代码崩溃了。但有了这个,Category范围将只显示organization_id:nil。
有人有任何想法吗?
非常感谢!
答案 0 :(得分:0)
@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)