Quick question to see how I might re-sort an Activerecord data set.
say I have this table:
| id | student | score | avg_for_year
1, steve, 85, 82
2, tom, 84, 92,
3, jim, 92, 95
In my controller, I have something like:
t= Testscores.find(:all, :order => “score DESC”, :limit => 2)
…where it would return the records for Jim and Steve…
My question is:
Is it possible to sort the resulting array “t” by name?
Where if I want to render this collection in a view, I could render it
sorted by the students name, rather than their test score.
The key point is that I am taking only 2 of the 3 records based on their
test score and then sorting the returned students alphabetically rather
by test score.
I’ve tried things like t.sort.name and other variations. I also thought
I could loop through t and push data to a new array and sort that, but
doesn’t seem very clean.
My example is more complicated but that is the gist.