我刚刚将Ruby 2.2.2升级到2.3.0。每当我运行rake任务时,我都会收到以下错误:
Christians-Air:my_rails_app cman77$ rake --trace
rake aborted!
NameError: uninitialized constant I18n::Config::Backend
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n/config.rb:19:in `backend'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n.rb:147:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/actionview-4.2.6/lib/action_view/helpers/translation_helper.rb:69:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n/config.rb:19:in `backend'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n.rb:147:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/actionview-4.2.6/lib/action_view/helpers/translation_helper.rb:69:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `block in run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `each'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/application.rb:452:in `run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:453:in `load_tasks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/railtie.rb:194:in `public_send'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/railtie.rb:194:in `method_missing'
/Users/cman77/Dropbox/rails_projects/my_rails_app/Rakefile:9:in `<top (required)>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:689:in `raw_load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:77:in `block in run'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/rake:23:in `load'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/rake:23:in `<main>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/ruby_executable_hooks:15:in `<main>'
任何人都有这方面的经验吗?我真的被困在如何开始诊断/解决这个问题。
以下是我的Rakefile的内容:
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
ENV['NEWRELIC_ENABLE'] = 'false'
MyRailsApp::Application.load_tasks
这似乎是I18n gem中引用的违规行: https://github.com/svenfuchs/i18n/blob/master/lib/i18n/config.rb#L18
更新:它似乎与我的一个rake文件中使用include ActionView::Helpers::TranslationHelper
有关。如果我删除该行,我可以运行rake命令。
Update2 :删除include ActionView::Helpers::TranslationHelper
并将(t "some_text")
替换为(I18n.t "some_text")
完全解决了问题。我还是会给那些可以解释为什么会破坏Ruby升级的人奖励!
答案 0 :(得分:1)
我的猜测是你遇到了这个问题,因为你在rake任务中使用t
方法(控制器和视图的助手),而不是标准的I18n.t
。
这是一种不常见且非传统的方法,所以你已经陷入few have experienced的可能回归中,并且它有一个简单的解决方案,就像你找到的那样:坚持惯例。