Commit cb20f270

mo khan <mo@mokhan.ca>
2014-05-21 03:48:49
add migration to move categories from old join table to category_id on creations table.
1 parent 5b9a40d
app/controllers/categories_controller.rb
@@ -2,7 +2,6 @@ class CategoriesController < ApplicationController
   def show
     @category = Category.find_by_slug(params[:slug].downcase)
     if @category
-      @categories = Category.all
       @creations = @category.creations.includes(:user).page(params[:page]).per(12)
     else
       redirect_to creation_tag_path(params[:slug].downcase)
db/migrate/20130221134059_migrate_categories_to_tags.rb
@@ -1,15 +1,15 @@
 class MigrateCategoriesToTags < ActiveRecord::Migration
   def up
-    ["Fondant", "Butter Cream", "Tiered", "3D", "Birthday", "Wedding", "Holiday", "Theme", "Anniversary", "Baby Shower", "Naughty Cakes"].each do |category|
-      Creation.joins(:categories).where(:categories => {:name => category }).each do |creation|
-        local_creation = Creation.find(creation.id)
-        local_tags = local_creation.tags.map{ |tag| tag.name }
-        local_tags.push(category)
-        creation.user.tag(local_creation, :with => local_tags, :on => :tags)
-        local_creation.save!
-      end
-      Category.find_by_name(category).destroy if Category.find_by_name(category)
-    end
+    #["Fondant", "Butter Cream", "Tiered", "3D", "Birthday", "Wedding", "Holiday", "Theme", "Anniversary", "Baby Shower", "Naughty Cakes"].each do |category|
+      #Creation.joins(:categories).where(:categories => {:name => category }).each do |creation|
+        #local_creation = Creation.find(creation.id)
+        #local_tags = local_creation.tags.map{ |tag| tag.name }
+        #local_tags.push(category)
+        #creation.user.tag(local_creation, :with => local_tags, :on => :tags)
+        #local_creation.save!
+      #end
+      #Category.find_by_name(category).destroy if Category.find_by_name(category)
+    #end
   end
 
   def down
db/migrate/20140521032101_migrate_categories_from_join_table_to_creations.rb
@@ -0,0 +1,8 @@
+class MigrateCategoriesFromJoinTableToCreations < ActiveRecord::Migration
+  def up
+    execute("UPDATE creations AS c SET category_id = cat.category_id FROM creations_categories AS cat WHERE c.id = cat.creation_id")
+  end
+
+  def down
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140520023608) do
+ActiveRecord::Schema.define(version: 20140521032101) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
spec/features/upload_creation_spec.rb
@@ -18,7 +18,7 @@ describe "uploading a new creation", :js => true do
       fill_in("creation_name", :with => "yummy cake")
       fill_in("creation_watermark", :with => "yummy")
       fill_in("creation_story", :with => "this was just so damn yummy so i ate it alone.")
-      select(category_2.name, :from => 'creation_category')
+      select(category_2.name, :from => 'creation_category_id')
       #fill_in("creation_tags", :with => "cake, yummy")
     end
     click_button("NEXT STEP")