cirandas.net

ref: master

db/migrate/20130626152300_add_product_categories_block_to_enterprises.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class AddProductCategoriesBlockToEnterprises < ActiveRecord::Migration
  def self.up
    Enterprise.find_each do |enterprise|
      enterprise.boxes << Box.new while enterprise.boxes.length < 2
      enterprise.boxes[1].blocks << ProductCategoriesBlock.new
    end
  end

  def self.down
    Enterprise.find_each do |enterprise|
      enterprise.boxes.each do |box|
        box.blocks.each do |block|
          block.destroy if block.class == ProductCategoriesBlock
        end
      end
    end
  end
end