Search code examples
ruby-on-railsglobalization

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


The docs for the Globalize3 gem are clear about how to create a translation table, but I don't see any information about how to add a field to a translation table during a later migration. For example, I initially included Category.create_translation_table! :name => :string when I created my Category model. Now, however, I need to add a translated field to the model.

How do I do that with a Rails migration? I don't see any docs for an alter_translation_table! method or anything similar...


Solution

  • With Globalize4, just :

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

    Don't forget to add the new field in your model :

    translate :name, :hint