Reputation: 40137
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?
Upvotes: 2
Views: 264
Reputation: 1084
check out https://github.com/mixonic/ranked-model, a better performing rewrite of acts_as_list.
This article shows you how to put it all together using jquery ui on the frontend: http://benw.me/posts/sortable-bootstrap-tables/
Upvotes: 0
Reputation: 4127
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
Upvotes: 2
Reputation: 544
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.
Upvotes: 3