swanandp/acts_as_list — Issue #17: decrement_positions_on_lower_items method
Author: piccio
Created: 2011-10-12 12:41:04+00:00
State: open

I found an odd behaviour when destroing a list item. when it's invoked decrement_positions_on_lower_items method al the lower items' position are set to deleted item's position. for example:

[ #
, #
, #
, #
]

if I delete the item with id = 2 the resulting list is:

[ #
, #
, #
]

instead of:

[ #
, #
, #
]

I resolved overriding decrement_positions_on_lower_items method:

# This has the effect of moving all the lower items up one.
def decrement_positions_on_lower_items
return unless in_list?
acts_as_list_class.each do |l|
l.update(
"#{position_column} = (#{position_column} - 1)",
"#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
)
end
end