I have this Json array of objects
"students": [{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"age": "14",
}, {
"id": 2,
"first_name": "Victoria",
"last_name": "Secret",
"age": "9",
}, {
"id": 3,
"first_name": "Jim",
"last_name": "Morrison",
"age": "16",
}, {
"id": 4,
"first_name": "Jack",
"last_name": "Daniels",
"age": "7",
},
}]
I want to display them in my index.html.erb
sorted by age in DESC order. I'm half way there, I have manage to sort them, however not in exact DESC order. This is my loop
<% @classroom['students'].sort_by { |st| st['age'] }.each do |student| %>
This is the result I want:
16, Jim, Morrison
14, John, Doe
9, Victoria, Secret
7, Jack, Daniels
This is what I get instead:
14, John, Doe
16, Jim, Morrison
7, Jack, Daniels
9, Victoria, Secret