在Heroku语言环境弃用警告上部署Rails 4.0.2

时间:2014-01-05 19:58:00

标签: ruby-on-rails heroku

我已更新到Rails 4.0.2,我收到了弃用警告:

  

[已弃用] I18n.enforce_available_locales默认为true   未来。如果您真的想跳过您的语言环境验证   可以设置I18n.enforce_available_locales = false以避免此消息。

为了摆脱警告,我决定设置:

I18n.config.enforce_available_locales = true
config.i18n.default_locale = :es

在我的config / application.rb文件中。

它适用于开发但是当我将我的工作部署到Heroku时,我得到以下错误:

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       :es is not a valid locale
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n.rb:288:in `enforce_available_locales!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n/config.rb:32:in `default_locale='
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n.rb:35:in `default_locale='
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:41:in `block in initialize_i18n'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:34:in `each'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:34:in `initialize_i18n'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:15:in `block in <class:Railtie>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `call'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/config/environment.rb:5:in `<top (required)>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:250:in `block in run_tasks_blocks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'

任何想法如何避免此错误?

由于

2 个答案:

答案 0 :(得分:7)

我认为如果先设置config.i18n.available_locales = [:es],它应该会有用。

答案 1 :(得分:1)

这个错误:

  

原因是由于语言环境中存在语言国家/地区的错误   格式。好消息是它已经修好了。这是   在Github中使用Issue 13164进行了报告,并使用pull request 229进行了修复。

阅读this了解详情

config.i18n.enforce_available_locales = boolean

如果您使用false:
这跳过了语言环境验证 不关心语言环境
如果您使用true:
希望应用程序在传递无效区域设置时引发错误(或) 想默认为新的Rails行为(或) 关心区域设置验证