Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `create_translation_table!'

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?

like image 834
Dougui Avatar asked Dec 17 '12 00:12

Dougui


3 Answers

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.

like image 88
Michael Franzl Avatar answered Sep 21 '22 06:09

Michael Franzl


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

like image 27
jent zheng Avatar answered Sep 22 '22 06:09

jent zheng


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

like image 42
I. Hryhoryshyn Avatar answered Sep 19 '22 06:09

I. Hryhoryshyn