zorab47 / active_admin-sortable_tree

Show ActiveAdmin index as a nested tree with drag'n'drop
MIT License
162 stars 127 forks source link

Dragging causes all records to update sort attribute #34

Closed kiddrew closed 9 years ago

kiddrew commented 10 years ago

First, let me say thanks for the gem. It's very handy.

I just dragged one node so that its parent is now another node in the tree. I notice two things:

  1. It executes an update on every record in the table (odd)
  2. The update statement is like this:

UPDATE "ingredients" SET "ancestry" = $1, "name" = $2, "updated_at" = $3 WHERE "ingredients"."id" = 25 [["ancestry", "24"], ["name", 1], ["updated_at", "2014-07-15 21:11:22.834266"]]

The "name" field (my sort attribute) was the name of an ingredient before the move, so something like "nutmeg". The move caused every record in my table to be updated with names that are sequential integers. So the first record is now named "0", the second "1", the third "2", etc. This happened to all 20 records I had in the table.

Anyone have any idea what I'm doing wrong?

zorab47 commented 10 years ago

The plugin assumes that sortable_attribute (#position by default) is a field used internally to sort the items. It is best to use a hidden attribute to store the item's sorted positions.

zorab47 commented 9 years ago

@kiddrew any updates on this?

kiddrew commented 9 years ago

When I couldn't get it to work initially, I removed the gem and I haven't revisited. I'll close this for now.