I am getting info from my database
@teams = Team.select(:id,:name)
Then, I am rendering this info with an assosiation
render json: @teams, include: :players
This produce me the following input:
[
{
"id": 1,
"name": "Lyon Gaming",
"players": [
{
"name": "Jirall",
"position": "Superior",
},
{
"name": "Oddie",
"position": "Jungla",
}
]
}
]
How ever I need to sort the players in an specific order (not alphabetical)
I already have the sql statement to do it; how ever I dont know how to apply this method to each association.
I am looking something like:
render json: @teams, (include: :players, method: custom_order)
But this raise me an error.
Any ideas?