Browse Source

fixup! Use translation tables for PublicBodyCategory and PublicBodyHeading

use-local-geoip-if-possible
Louise Crow 7 years ago
parent
commit
d0a21efb71
  1. 10
      db/migrate/20140716131107_create_category_translation_tables.rb

10
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?

Loading…
Cancel
Save