Ruby on Rails: Sort Array Records By Enum Value

Order.all.order(:shipment_mode)
Order.all.order(shipment_mode: :desc)
class Order < ApplicationRecord
include ::EnumValueConcern
enum shipment_mode: {
truck: 1,
sea: 2,
air: 3
}, _prefix: true
def numeric_shipment_mode_value
self.class.shipment_modes[shipment_mode]
end

end

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
icelandcheng

icelandcheng

67 Followers

Programming Skill learner and Sharer | Ruby on Rails | Golang | Vue.js | Web Map API