Created
October 25, 2012 12:24
-
-
Save detomastah/3952291 to your computer and use it in GitHub Desktop.
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
begin | |
$counter = 0 | |
def update_positions(scope, start) | |
scope.each_with_index do |ia, index| | |
ia.update_attribute(:position, start + index) | |
$counter += 1 | |
end | |
end | |
Product.all.each do |p| | |
ia = p.image_assignments.where("position IS NOT NULL").order("position DESC").first | |
scope = p.image_assignments.where("position IS NULL") | |
if ia | |
update_positions(scope, ia.position + 1) | |
else | |
update_positions(scope, 0) | |
end | |
end | |
puts $counter | |
end;nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment