2014-01-26 1 views
1

저는 레일스에서 ​​보석에 약간의 문제가 있습니다. i18n-active_record gem을 설치했습니다 (레일 4와 루비 2 사용). 내 보석에 나는 모델 및i18n-active_record PG :: Error : ERROR : relation "translations"가 존재하지 않습니다 (레일 4)

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 

가 지금은 설치 번들 실행할 수있는 마이그레이션을 생성 한, 그리고 보석이 설치됩니다, 그래서 이것은 또한 모델 번역을 필요로

gem 'i18n-active_record', 
     :git => 'git://github.com/svenfuchs/i18n-active_record.git', 
     :require => 'i18n/active_record' 

파일. 내가 갈퀴 DB를 실행하려고한다면 : 내가 먼저 gemfile에 보석을 추가하고 번들 설치를 실행 한 후 마이그레이션을 실행하여이 일을 주위에 와서 내 로컬 서버에서 오류

PG::Error: ERROR: relation "translations" does not exist (and some other stuff) 

을 얻을 마이그레이션 할 수 있습니다. 그러나 gem 파일이 최신이 아니기 때문에 gemfile에 있어야합니다. 왜냐하면 레이크 마이그레이션을 실행할 수 없기 때문입니다.

하지만 지금은 이것을 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 
+0

당신이 모델'Translation'를 생성 한 추가 할 필요가 해결 있어요? –

+0

예. 나는 이미이 기둥에 대답했다. 내 문제는 첫 번째 게시물에서 편집 후에 설명 된 코드를 추가하여 해결되었습니다. 어쨌든 Thx : D –

+0

스스로 대답 ... –

답변

1

나는 이것이 내가 표는 초기화 (locale.rb)에있는 경우

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 
관련 문제