Created
October 1, 2012 15:21
-
-
Save benwoodward/3812452 to your computer and use it in GitHub Desktop.
An expensive transaction in acts_as_list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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