In rails 3.1
I want to make the db records movables, with a Move up and a Move down link in ecah one. For example, if I have 4 records:
Title 1 [up] [开发者_JS百科down]
Title 2 [up] [down]
Title 3 [up] [down]
Title 4 [up] [down]
I could click in the Title 3's up link and the new table would be:
Title 1 [up] [down]
Title 3 [up] [down]
Title 2 [up] [down]
Title 4 [up] [down]
Add an Order field to the Table. Then when the person clicks the move up or move down, add or subtract 1 from that field. Make sure this field doesn't go below 0 or above the number of entries - 1 in your table. When you wan't to display these fields in order, just order them by this field.
Moving rows 'up and down' in a database (SQL query help)
精彩评论