Quick question to see how I might re-sort an Activerecord data set.
Let’s
say I have this table:
tablename: testscores
| 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
than
by test score.
I’ve tried things like t.sort.name and other variations. I also thought
that
I could loop through t and push data to a new array and sort that, but
it
doesn’t seem very clean.
My example is more complicated but that is the gist.
Thanks.
Steve O.
http://www.smarkets.net