Commit c35f5446

mo k <mo@mokhan.ca>
2013-02-21 14:30:27
start migration script to move categories to tags.
1 parent 8525bbc
db/migrate/20130221134059_migrate_categories_to_tags.rb
@@ -0,0 +1,21 @@
+class MigrateCategoriesToTags < ActiveRecord::Migration
+  def up
+    #Add 5 categories 1)Cake 2)Cupcake 3)Cake Pop 4) Cookie 5)Other
+    ["Fondant", "Butter Cream", "Tiered", "3D", "Birthday", "Wedding", "Holiday", "Theme", "Anniversary", "Baby Shower", "Naughty Cakes"].each do |category|
+      p category
+      Creation.joins(:categories).where(:categories => {:name => category }).each do |creation|
+        p "    #{creation.name} with #{category}"
+        local_creation = Creation.find(creation.id)
+        local_tags = local_creation.tags.map{ |tag| tag.name }
+        local_tags.push(category)
+        p "before #{local_tags}"
+        creation.user.tag(local_creation, :with => local_tags, :on => :tags)
+        p "after #{local_creation.tags}"
+        local_creation.save!
+      end
+    end
+  end
+
+  def down
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20121217172714) do
+ActiveRecord::Schema.define(:version => 20130221134059) do
 
   create_table "active_admin_comments", :force => true do |t|
     t.integer  "resource_id",   :null => false