Skip to content

Instantly share code, notes, and snippets.

@detomastah
Created October 25, 2012 12:24
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 detomastah/3952291 to your computer and use it in GitHub Desktop.
Save detomastah/3952291 to your computer and use it in GitHub Desktop.
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