diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-09-26 13:20:13 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-09-26 13:20:13 +0100 |
commit | d0a21efb7170057a78abc88e7bee929714edc302 (patch) | |
tree | 715c23b82464190bf73b73194e5764e0ef5d3775 | |
parent | 9599df75c8d3b63b3952861d830500744f3f6635 (diff) |
fixup! Use translation tables for PublicBodyCategory and PublicBodyHeading
-rw-r--r-- | db/migrate/20140716131107_create_category_translation_tables.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/db/migrate/20140716131107_create_category_translation_tables.rb b/db/migrate/20140716131107_create_category_translation_tables.rb index 3fe50ad33..f4b90b330 100644 --- a/db/migrate/20140716131107_create_category_translation_tables.rb +++ b/db/migrate/20140716131107_create_category_translation_tables.rb @@ -1,4 +1,10 @@ class CreateCategoryTranslationTables < ActiveRecord::Migration + class PublicBodyCategory < ActiveRecord::Base + translates :title, :description + end + class PublicBodyHeading < ActiveRecord::Base + translates :name + end def up default_locale = I18n.locale.to_s @@ -47,7 +53,7 @@ class CreateCategoryTranslationTables < ActiveRecord::Migration # copy current values across to the default locale PublicBodyHeading.where(:locale => default_locale).each do |heading| heading.translated_attributes.each do |a, default| - value = category.read_attribute(a) + value = heading.read_attribute(a) unless value.nil? heading.send(:"#{a}=", value) end @@ -58,7 +64,7 @@ class CreateCategoryTranslationTables < ActiveRecord::Migration # copy current values across to the non-default locale(s) PublicBodyHeading.where('locale != ?', default_locale).each do |heading| default_heading = PublicBodyHeading.find_by_name_and_locale(heading.name, default_locale) - I18n.with_locale(category.locale) do + I18n.with_locale(heading.locale) do heading.translated_attributes.each do |a, default| value = heading.read_attribute(a) unless value.nil? |