在我的rails代码中,我需要根据记录的日期和记录所接收到的投票组合来查询表格。我在rails中通过以下方式实现:
if params[:sort_by] == "default"
objs1 = class_name.where("created_at between '#{Date.today - 7}' and '#{Date.today}' and net_votes > 0").order("net_votes DESC")
objs2 = class_name.where("created_at between '#{Date.today - 30}' and '#{Date.today - 7}' and net_votes > 0").order("net_votes DESC")
objs3 = class_name.where("created_at between '#{Date.today - 90}' and '#{Date.today - 30}' and net_votes > 0").order("net_votes DESC")
objs4 = class_name.where("created_at < '#{Date.today - 90}' and net_votes > 0").order("net_votes DESC")
objs = objs1 + objs2 + objs3 + objs4
除了效率之外,我无法在组合查询结果上使用分页功能,更不用说代码非常丑陋了。应该如何正确处理呢?
提前感谢。