When you change current_link.location in this way, you are potentially
creating a situation where two records have the same location. Then you
search by the same value, so you’ll find one of the two with that
If you’re unlucky, you’ll find the one you just changed, and will just
setting it back to its original value again.
I suggest looking at AWDR, p. 254, which describes acts_as_list and
position. Just another reason why I love Rails!
From: “Human D.” firstname.lastname@example.org
I have a link table with a location field, here is the code I wrote to
reorder the rows
move_up action in links controller
current_link = Link.find(params[:id])
current_link.location -= 1
same_link = Link.find_by_location(current_link.location)
same_link.location += 1
redirect_to :action => 'list'
But it does not work always, can’t figure it out.
What may be the problem?
Is there a better way to do this?
Rails mailing list