views:

9

answers:

0

I am displaying a list of articles. I sort my articles by the param order and I want when displaying the list of article to be able to "move" them up or down.

In php I do everything with a for browsing my array of results and inside the for I go to the next index to find where I am in the list, and with which other article I must swap my order. I can do that in the script displaying the edit page and then in the script executing the update. In rails i have only a form_for in erb. How can I:

  • Know if my entry is the last one or the first one (display only V for the first, ^ for the last and V^ for the rest)

  • Update my DB entry by switching the order value between the article that I want to lower, raise, and the one it's place it is taking.