Sha256: 682f02a7f77dc066941b497261332e50f5f4328ea4d5f3af14685c0b77f446b2
Contents?: true
Size: 907 Bytes
Versions: 5
Compression:
Stored size: 907 Bytes
Contents
class LocalizePublishColumn < ActiveRecord::Migration def up rename_column :qbrick_pages, :published, :published_en add_column :qbrick_pages, :published_de, :integer, default: 0 I18n.available_locales.each do |locale| column_name = :"published_#{locale.to_s.underscore}" add_column :qbrick_pages, column_name, :integer, default: 0 unless column_exists? :qbrick_pages, column_name end new_translations = Qbrick::Page.translated_columns_for(:published) - %w(published_en) Qbrick::Page.all.each do |page| page.update_columns Hash[new_translations.zip([page.published_en] * new_translations.count)] end end def down translated_columns = Qbrick::Page.translated_columns_for(:published) - %w(published_en) rename_column :qbrick_pages, :published_en translated_columns.each do |column| remove_column :qbrick_pages, column end end end
Version data entries
5 entries across 5 versions & 1 rubygems