mardi 31 mai 2016

Move one object in collection of objects in rails

Here is the scenario, I have these objects. Let's assume that this is a User:

The object came from:

@user = User.all

User Object

[<#User id: 1, firstname: "John", lastname: "Pond">,<#User id: 2, firstname: "Paul", lastname: "Rich">,<#User id: 3, firstname: "Jasmine", lastname: "Ong">]

How can I move one object up, for example I want to move User.id == 2? The result I want is shown below.

[<#User id: 2, firstname: "Paul", lastname: "Rich">,<#User id: 1, firstname: "John", lastname: "Pond">,<#User id: 3, firstname: "Jasmine", lastname: "Ong">]

Aucun commentaire:

Enregistrer un commentaire