I used the below approach;
User.find(previous id value).update_column(:id, new id value)
For example, id value of 1st row is 1 and id value of third row is 2 and to place the highlighted row whose id value is 3 in between.
At first we will change the id value = 2 to 4 and consequently change the id value = 3 to 2 hence the result.Hope everything is clear.
0
solved How can I insert a new database record in the middle of an existing table?