Rails 7 adds in_order_of for ActiveRecord::QueryMethods and Enumerable

Quite often in our Rails application, we need to retrieve records sorted in a specific order. For example, in an e-commerce application, we want to retrieve the customer orders in the order of "Completed, Cancelled, In Transit, Pending" statuses. The way to do it is to write an explicit SQL query. Starting Rails 7, this can be achieved simply with the help of the in_order_of method for ActiveRecord::QueryMethods and Enumerable. This article explains how we can use the in_order_of method to sort data in Rails 7. 1. ActiveRecord::QueryMethods#in_order_ofConsider we have a