Sha256: 2a9fd5f6fd7282cb56a006f9bda6bf36f94e9a9531e387eca6883f2c45b40a27

Contents?: true

Size: 884 Bytes

Versions: 6

Compression:

Stored size: 884 Bytes

Contents

class DropsCategoriesForTags < ActiveRecord::Migration
  class Categorization < ActiveRecord::Base
    belongs_to :article
    belongs_to :category
  end

  class Category < ActiveRecord::Base
    has_many :categorizations
    has_many :articles, :through => :categorizations
  end

  def up
    # First, we migrate categories into tags
    Category.find_each do |cat|
      # Does a tag with the same permalink exist?
      tag = Tag.find_or_create_by(name: cat.permalink) do |tg|
        tg.display_name = cat.name
      end

      redirect = Redirect.create(from_path: "category/#{cat.permalink}",
                                 to_path: File.join(Blog.first.base_url, "tag", tag.name))
      cat.articles.each do |article|
        article.tags << tag
        article.save
      end
    end

    drop_table :categorizations
    drop_table :categories
  end

  def down
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
publify_core-9.0.0.pre6 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.0.0.pre5 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.0.0.pre4 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.0.0.pre3 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.0.0.pre2 db/migrate/115_drops_categories_for_tags.rb
publify_core-9.0.0.pre1 db/migrate/115_drops_categories_for_tags.rb