aboutsummaryrefslogtreecommitdiffstats
path: root/db/migrate/096_create_translation_tables.rb
blob: 4b47c11f7bc0c3a66eba5325b0822ed3fe2c0ba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class CreateTranslationTables < ActiveRecord::Migration
  def self.up
    fields = {:name => :text, 
      :short_name => :text,
      :request_email => :text,
      :url_name => :text,
      :notes => :text,
      :first_letter => :string, 
      :publication_scheme => :text}
    PublicBody.create_translation_table!(fields)

    # copy current values across to default locale
    PublicBody.all.each do |publicbody|
      publicbody.translated_attributes.each do |a, default|
        value = publicbody.read_attribute(a)
        unless value.nil?
          publicbody.send(:"#{a}=", value)
        end
      end
      publicbody.save!
    end
  end


  def self.down
    PublicBody.drop_translation_table!
  end
end