Skip to content

Instantly share code, notes, and snippets.

@benwoodward
Created October 1, 2012 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benwoodward/3812452 to your computer and use it in GitHub Desktop.
Save benwoodward/3812452 to your computer and use it in GitHub Desktop.
An expensive transaction in acts_as_list
# This has the effect of moving all the lower items up one.
def decrement_positions_on_lower_items(position=nil)
return unless in_list?
position ||= send(position_column).to_i
acts_as_list_class.unscoped.update_all(
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{position}"
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment