I have an array of objects
@posts = [ {
"post": {
"id":33,"title":"1","body":"","created_at":"2022-01-16T16:54:11.911Z","updated_at":"2022-01-16T16:54:25.642Z","user_id":3,"archive":null,"public_id":1
},
"attachments":[],
"tags": []
},
{
"post": {
"id":33,"title":"1","body":"","created_at":"2022-01-16T16:54:11.911Z","updated_at":"2022-01-16T16:54:25.642Z","user_id":3,"archive":null,"public_id":1
},
"attachments":[],
"tags": []
},
{
"post": {
"id":33,"title":"1","body":"","created_at":"2022-01-16T16:54:11.911Z","updated_at":"2022-01-16T16:54:25.642Z","user_id":3,"archive":null,"public_id":1
},
"attachments":[],
"tags": []
},
]
I want to sort by the post.created_at
column for the array collection
I have tried
render json: @posts.sort_by { |h| h.created_at.split('/').reverse }
But am getting undefined method
created_at' for #<Hash`