我有 2 个类似的查询,我怎样才能把它们弄干?两个查询之间只有 1 个条件不同。
if self.gender_target == "Both"
return Drop.limit(180).live.where(
:drops => {:navigation_section_id => 1}
).group(:id).joins(:categories).where(
:categories => {:id => self.categories}
).all
end
if self.gender_target != "Both"
return Drop.limit(180).live.where(
:drops => {:navigation_section_id => 1},
:drops => {:gender_target => ["Both", self.gender_target]} #extra condition
).group(:id).joins(:categories).where(
:categories => {:id => self.categories}
).all
end