"Sorting and filtering are best performed in the database, if possible, using ActiveRecord's tools."
this needs a big fat asterisk.
sometimes sorting in the database requires a filesort
if you know ahead of time roughly how many results are getting sorted in-memory it absolutely can be faster to do it in-memory than ask the database to do it