Sha256: 898f8871363d70030ed71ef737de27433ac29f755d957cf1632ac605c5ced41e
Contents?: true
Size: 678 Bytes
Versions: 6
Compression:
Stored size: 678 Bytes
Contents
class AddPositionToPages < ActiveRecord::Migration def self.up add_column :pages, :position, :integer Page.reset_column_information say_with_time("Putting all pages in a default order...") do ActiveRecord::Base.record_timestamps = false Page.where(parent_id: nil).each do |p| put_children_into_list(p) end ActiveRecord::Base.record_timestamps = true end end def self.down remove_column :pages, :position end def self.put_children_into_list(page) page.children.order("title asc").each_with_index do |pg, idx| pg.update_attribute('position', idx + 1) put_children_into_list(pg) end end end
Version data entries
6 entries across 6 versions & 1 rubygems