access following entry in a form_for, and switch a value between two entry of my DB
Posted
by Sylario
on Stack Overflow
See other posts from Stack Overflow
or by Sylario
Published on 2010-05-28T00:30:07Z
Indexed on
2010/05/28
0:31 UTC
Read the original article
Hit count: 602
ruby-on-rails
|sorting
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 wich 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 my form_for in my 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 he is taking the place.
© Stack Overflow or respective owner