我想按评论日期检索最后五篇文章,但我想按时间顺序(升序)显示它们。我该怎么做呢?
# controller
@recent_articles = Article.where("reviewed = ?", true).order("review_date DESC").limit(5)
# view
<% @recent_articles.each do |ra| %>
# articles sorted by review_date in ascending order
<% end %>
我尝试在控制器中执行此操作,但它检索了最旧的五个review_dates
(即它只是按 ASC 顺序检索记录,而不是对已检索到的数组重新排序):
@recent_articles = Article.where("reviewed = ?", true).order("review_date DESC").limit(5)
@recent_articles = @recent_articles.reorder("review_date ASC")