I'm using acts_as_list v0.9.17 this way:
class ListItem < ActiveRecord::Base
acts_as_list scope: [:column1_id, :column2_id], :add_new_at => :bottom
end
When a new (scoped) @list_item
is created, say the one where column1_id
is 1
, column2_id
is 11
and column3_id
is 37
, the database looks as follows, as expected:
id | position | column1_id | column2_id | column3_id
--- | -------- | ---------- | ---------- | ----------
750 | 1 | 1 | 11 | 89
751 | 2 | 1 | 11 | 56
752 | 3 | 1 | 11 | 105
753 | 4 | 1 | 11 | 25
754 | 5 | 1 | 11 | 37
However, when a @list_item
is destroyed, say the one where column1_id
is 1
, column2_id
is 11
and column3_id
is 56
(record id 751
), then the database looks as follows:
id | position | column1_id | column2_id | column3_id
--- | -------- | ---------- | ---------- | ----------
750 | 1 | 1 | 11 | 89
752 | 3 | 1 | 11 | 105
753 | 4 | 1 | 11 | 25
754 | 5 | 1 | 11 | 37
That means there is a gap for position
2
.
How to prevent or adjust the gap? That is, how to handle reordering of list items when a list item is destroyed?
Note: I know there are methods that change position and reorder list but I don't know whether
and how to use them to solve the issue (maybe using someway remove_from_list
).