ruby-on-railsinternationalizationglobalize

How to specify translation table name. Globalize


I've got a translation table for Category model in my app.

I have to create an additional table for model Article::Category with Globalize gem.

Category migration contains follow reversible creation:

reversible do |dir|
  dir.up do
    Category.create_translation_table! name: :string,
                                       description: :text
  end

  dir.down do
    Category.drop_translation_table!
  end
end

Article::Category migration has almost the same

reversible do |dir|
  dir.up do
    Article::Category.create_translation_table! title: :string
  end

  dir.down do
    Article::Category.drop_translation_table!
  end
end

When I'm trying to db:migrate I've got an error: PG::DuplicateTable: ERROR: relation "category_translations" already exists

How to specify table name while module already specified in migration (Article::Category.create_translion_table!)

There is no method or option in globalize gem to specify table name. I wish to do it without overriding Article::Category class name.


Solution

  • Solved by adding

    def self.table_name_prefix
      'article_'
    end
    

    In Article module declaration

    module Article
      def self.table_name_prefix
        'article_'
      end
    end