You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
10 lines
262 B
10 lines
262 B
5 years ago
|
class ReorderCooImgPosition < ActiveRecord::Migration[5.2]
|
||
|
def change
|
||
|
CooImg.all.group_by(&:img_type).each do |_type, objs|
|
||
|
objs.sort_by(&:position).each_with_index do |obj, index|
|
||
|
obj.update!(position: index + 1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|