我如何用我的排序结果指数featured_end_date >= Time.now()
在:asc
订单,然后排序由有结果的其余部分publish_at: :desc
。
目前我有BlogPost.order(featured_end_date: :asc, publish_at: :desc)
. 我错过了那个>= Time.now()
比较。
我认为可能需要使用范围,但我不确定如何实现这一点。
博客帖子模型
scope :featuredfuture, -> { where("featured_end_date >= ?", Time.now()).order(featured_end_date: :asc) }
scope :other, -> { where("featured_end_date < ? or featured_end_date is null", Time.now()).order(publish_at: :desc) }
控制器
@blogposts = BlogPost.featuredfuture + BlogPost.other
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句