I have multiple instances of data displayed in tables that need to be sorted – much of this data is calculated from the table and isn’t just a raw value in the table.
A simple example: Column A = User.visits / User.membership_term
I’m using sortable table columns: http://railscasts.com/episodes/228-sortable-table-columns.
I’ve tried putting the calculation in the controller and adding a class method to my model but neither seems to work. How can I sort by a calculated field?
You can always use the basic sort method:
So you can sort your array of active records using similar ways.