Rails: Reordering an Array
I want to retrieve the last five Articles by review date, but I want to
display them in chronological order (ascending order). How do I do this?
# 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 %>
I tried doing this in the controller, but it retrieved the five oldest
review_dates instead (i.e. it just retrieved the records by ASC order
instead of reordering the array already retrieved):
@recent_articles = Article.where("reviewed = ?", true).order("review_date
DESC").limit(5)
@recent_articles = @recent_articles.reorder("review_date ASC")
No comments:
Post a Comment