Rails Globalize3 gem: How do I add an extra field to the translation table using migration?

The documents for Globalize3 pearls clearly indicate how to create a translation table, but I do not see any information on how to add a field to the translation table during the subsequent migration. For example, I first included Category.create_translation_table! :name => :string Category.create_translation_table! :name => :string when I created my category model. Now, however, I need to add the translated field to the model.

How to do this with Rails migration? I do not see any documents for the alter_translation_table! method alter_translation_table! or something like that ...

+7
source share
3 answers

Using Globalize4 is simple:

 class AddHintToCategory < ActiveRecord::Migration def up Category.add_translation_fields! hint: :text end def down remove_column :category_translations, :hint end end 

Remember to add a new field to your model:

 translate :name, :hint 
+8
source

You can do it manually, something like the following:

 class AddNewFieldToYourTable < ActiveRecord::Migration def self.up change_table(:your_tables) do |t| t.string :new_field end change_table(:your_table_translations) do |t| t.string :new_field end end def self.down remove_column :your_tables, :new_field remove_column :your_table_translations, :new_field end end 
+12
source

https://github.com/globalize/globalize/blob/master/lib/globalize/active_record/migration.rb:34 line (globalize 4)

 add_translation_fields!(fields, options) 

PS Just a typo in the previous comment, 'add_transaction_fields' is undefined.

+1
source

All Articles