Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - ActiveRecord and reverse sort

I have following data in database:

1
2
3
4
5

And I would like to get to output this:

3
4
5

I need it to print in the view:

<%car.colors.limit(3).order('created_at ASC').each do |color|%>
  ...

I know that exists reverse_order, but exist something like reverse sort?

(I know that is possible to load the data into an array and then go through the array, but this way is not very efficient)

like image 250
user984621 Avatar asked Feb 13 '12 17:02

user984621


1 Answers

How about just doing

<%car.colors.limit(3).order('created_at DESC').reverse.each do |color|%>
like image 131
Chowlett Avatar answered Oct 17 '22 05:10

Chowlett