I recently had a small challenge to order the records of a model by “day of week” . Records with day of week as Monday should appear on the top and stack multiple records of the same day.
Setting up the models:
In order to achieve this, I took a very simple approach. I use, Activerecord::Enum module in rails to build this. I first added a column called day_of_week
In the class_schedule model, we would need to define the enum with the days of the week :
The order in enum definition is extremely important. So in our database, data in day_of_week column would look something like the following :
Monday = 0 .. Sunday = 6
In order to add this as a selectbox in our activeadmin form :