我想按檢索日期檢索最後五篇文章,但我想按照時間順序(升序)顯示它們。我該怎麼做呢?Rails:重新排序ActiveRecord結果集
# 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")