views:

31

answers:

2

This is a tad different from rememebering say sort-by-date or sort-by-alphabet. I have a list of Items, that I'd like to allow the User to rearrange. More importantly, I'd like to remember that order. How would I do this?

+3  A: 

Use the acts_as_list act. Put acts_as_list in your model, add the field "position", which is an integer, to the table you want to sort, and create the new actions for the different sorts.

The documentation for acts_as_list that I linked to has code examples, but if you need more help, leave a comment and I'll edit this.

ahlatimer
If each user can access the same object you would need a mapping-class between those. Example: `User <- FavoriteShopItem -> ShopItem` and `acts_as_list` on `FavoriteShopItem`.
Marcel J.
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.

Also, the correct link is github.com/rails/acts_as_list

Xavier Shay