Sort by object attribute
Posted on 2008-11-06
Let me start by saying that my ultimate goal is to have a listing of items grouped by release date (using distance_of_time_in_words) and sorted in chronological order.
This is what I've done so far and it's not really working:
1) I have a model that has a release_date attribute
2) In the controller, converted the release_date value to distance_of_time_in_words
3) In the controller grouped all the objects with the same distance_of_time_in_words values together using group_by
4) In the view used model_name.keys.sort but what I get is an alphabetical sorting of the distance_of_time_in_words values (i.e. "2 Months", "5 Days", "6 Days", "about a month"). They do not sort chronologically.
So now my question is, how do I do a sort by an attribute of a value in a hash? What I want to do is sort by the model_name.release_date value. How do I structure the sort call to do that?