undefined method `create_translation_table!'
Asked Answered
I

3

10

I have a new rails engine and I want to use globalize3. I did this in my lib//engine.rb :

require 'globalize3'

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

Now, I try to create a migration like this :

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

And I have this error :

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

I think the file 'lib/globalize/active_record/migration.rb' is not loaded.

Any solution?

Irmgard answered 17/12, 2012 at 0:54 Comment(0)
U
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.

Undoubted answered 1/2, 2013 at 16:30 Comment(2)
This helped me a lot! Finally got it working this was the missing piece.Raber
Nice shot :) it fixed my issue :)Portamento
T
1

Try this

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

but the foreign key will become simplecms_page_id, I manually change it back to page_id

Tapioca answered 23/11, 2013 at 9:58 Comment(0)
M
1

In my case, globilize gem wasn't working correctly, because traco gem was also in Gemfile. Removing traco fixed the error. So I guess only using one of translation gems is allowed

Manchester answered 8/2, 2021 at 19:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.