9

我有一个新的 Rails 引擎,我想使用 globalize3。我在我的 lib//engine.rb 中做到了这一点:

require 'globalize3'

module SimpleCms
  class Engine < ::Rails::Engine
  end
end

现在,我尝试创建这样的迁移:

class CreatePages < ActiveRecord::Migration
  def up
    create_table :pages do |t|
      t.string :path
      t.timestamps
    end
    Page.create_translation_table! title: :string, body: :body
  end

  def down
    drop_table :pages
    Page.drop_translation_table!
  end
end

我有这个错误:

undefined method `create_translation_table!' for #<Class:0x00000001d5ca18>

我认为文件 'lib/globalize/active_record/migration.rb' 没有加载。

有什么解决办法吗?

4

3 回答 3

25

You have to add

translates :attributename

to your Engine model file before you run the migration. (Replace :attributename with the attribute you want to have translated). That fixed it for me.

于 2013-02-01T16:30:05.583 回答
1

尝试这个

SimpleCms::Page.create_translation_table! title: :string, body: :body

但是外键会变成simplecms_page_id,我手动改回page_id

于 2013-11-23T09:58:11.450 回答
1

就我而言,globilizegem 无法正常工作,因为tracogem 也在 Gemfile 中。删除traco修复了错误。所以我想只允许使用一种翻译宝石

于 2021-02-08T19:19:50.043 回答