C
C
CandyDandy2015-08-25 21:34:16
Ruby on Rails
CandyDandy, 2015-08-25 21:34:16

How to properly sort an ActiveRecord collection?

Hello!
The photos are sorted. How to correctly transfer a photo from id 2 to the place of the first key in the collection. And at the same time keep order. Thank you!
@photos = @gallery.gallery_photos.rank(:row_order)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Kononenko, 2015-08-26
@premas

Do you need end-to-end IDs? You don't need to touch the primary key. Add another column and increment it.

V
vsuhachev, 2015-08-27
@vsuhachev

There is acts_as_list to control the order in lists, I recommend

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question