Don't know enough about ActiveRecord to know if this can be written better, since it's going to be sorted in the controller, which may get unwieldy when there's a lot of records.