views:

48

answers:

2

I'm trying to implement a UI feature for a listings page where the user can change the order of the records they have created.

I'd assume one way to do it would be to store a position field with some kind of editable auto-increment rule; The position values of rows could then be swapped as the user raises or the lowers the position. However I'm not quite sure how that would be done, I'm still a Rails newbie.

I should also mention that I am trying to a avoid solutions that tie me to a particular database.

Any suggestions?

+2  A: 

acts_as_list is the standard solution here. You will have a position column in your model that will hold the ordering.

neutrino
Took me a few minutes to figure out plugins and correct usage, but it works really well! Thanks!
Greg Malcolm
A: 

This is a commment/addition to the accepted answer above.

acts_as_list is not designed for anything beyond a prototype, and out of the box it does not handle concurrency or data integrity at all. At the very least, you must set your isolation level to serializable! Here's a short screen cast with more information, and some workarounds.

Xavier Shay