【发布时间】:2015-03-23 11:32:01
【问题描述】:
我已将 hstore_translate 添加到具有现有数据的 Rails4 项目中。
class Product < ActiveRecord::Base
translates :subtitle, :description
end
config.i18n.fallbacks = true
class AddTranslationColumnsToProducts < ActiveRecord::Migration
def change
add_column :products, :subtitle_translations, :hstore
add_column :products, :description_translations, :hstore
end
end
如何访问我的旧字幕和说明字段?因为现在 Post.subtitle 和 Post.description 总是为零。回退不起作用还是我需要先迁移数据?
更新:
此迁移解决了问题。
class MigrateExistingDataToTranslations < ActiveRecord::Migration
def change
execute "UPDATE products p SET subtitle_translations=hstore('en',(select subtitle from products where id = p.id));"
execute "UPDATE products p SET description_translations=hstore('en', (select description from products where id = p.id));"
end
end
【问题讨论】:
标签: ruby-on-rails rails-i18n hstore globalize3