Thanks to this answer, I came up with the following:
order("role = 0 DESC, role = 1 DESC, role = 2 DESC")
Or, as an area with optional arguments:
scope :order_by_roles, -> (first = :admin, second = :ordinary, third = :manager) { order("role = #{User.roles[first]} DESC, role = #{User.roles[second]} DESC, role = #{User.roles[third]} DESC") }
source share