1
我在Rails中遇到了一个小问题。我已经安装了i18n-active_record gem(使用rails 4和ruby 2)。在我的宝石文件i18n-active_record PG ::错误:错误:关系“翻译”不存在(导轨4)
gem 'i18n-active_record',
:git => 'git://github.com/svenfuchs/i18n-active_record.git',
:require => 'i18n/active_record'
这也需要一个模型的翻译,所以我有一个生成的模型和迁移
class CreateTranslations < ActiveRecord::Migration
def self.up
create_table :translations do |t|
t.string :locale
t.string :key
t.text :value
t.text :interpolations
t.boolean :is_proc, :default => false
t.timestamps
end
end
def self.down
drop_table :translations
end
end
现在我可以捆绑运行安装,和创业板被安装。但是,如果我尝试运行耙分贝:迁移我得到我已经先运行迁移,然后加入宝石到Gemfile中并运行包安装来解决这个事情的错误
PG::Error: ERROR: relation "translations" does not exist (and some other stuff)
在我的本地服务器。但是,gem一定不能在gemfile中,因为如果是我无法运行rake migrate,因为gem文件不是最新的。
但现在我想在Heroku(或其他任何服务器)上推这个,我真的不想每次都这样做。有没有办法让我绕过这个循环?
编辑
我在github上得到了我的答案。我只是需要做的:
require 'i18n/backend/active_record'
if ActiveRecord::Base.connection.table_exists? 'translations'
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.send :include, I18n::Backend::Memoize
I18n::Backend::ActiveRecord.send :include, I18n::Backend::Flatten
I18n::Backend::Simple.send :include, I18n::Backend::Memoize
I18n::Backend::Simple.send :include, I18n::Backend::Pluralization
I18n.backend = I18n::Backend::Chain.new I18n::Backend::Simple.new, I18n.backend
end
你创建的模型'Translation'? –
是的。我已经在github上回答了这个问题。我的问题解决了添加我的第一篇文章中编辑后描述的代码。 Thx无论如何:D –
你自己回答... –