我有一个方法,之前是这样的
def circles
Circle.in(id: memberships.pluck(:circle_id))
end
加了一个参数,做了个判断,就平白多了很多行,请问有没有更简洁的写法,谢啦先!
def circles(status)
local_memberships = memberships
if (status)
local_memberships = local_memberships.where(status: status)
end
Circle.in(id: local_memberships.pluck(:circle_id))
end