看起来很简单 - 我想组合两个模型查询并按日期 DESC 对它们进行排序,但日期字段的名称不同。
@news_and_posts = [News.all(:limit => 3, :order => "date_of_news DESC") + Post.all(:limit => 3, :order => "date_of_post DESC")
我试过了
@news_and_posts = [News.all(:limit => 3, :order => "date_of_news DESC") + Post.all(:limit => 3, :order => "date_of_post DESC").sort_by {|n, p| [n.date_of_news, p.date_of_post]}
谢谢!