當我在我的模型運行Rspec的,我得到這樣的警告:的I18n棄用警告
(已廢棄)I18n.enforce_available_locales將默認爲true 未來。如果你真的想跳過你的語言環境驗證,你可以設置I18n.enforce_available_locales = false來避免這個消息。
我看到a similar question其中的解決辦法是設置我的config/application.rb中文件config.i18n.enforce_available_locales
或 I18n.config.enforce_available_locales
。我嘗試了兩種,但我仍然得到警告。
給我棄用警告的測試不使用除ActiveModel以外的任何Rails。不需要默認的spec_helper,我創建了自己的spec_helper,根本不涉及任何Rails。我也嘗試在我的自定義spec_helper中設置enforce_available_locales,但我得到了未初始化的常量錯誤。
我該如何擺脫棄用警告?
編輯: 下面是我的config/application.rb中與enforce_available_locales確切的代碼從我的嘗試之一
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Microblog
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
I18n.config.enforce_available_locales = true
end
end
你在'application.rb'中寫了什麼確切的代碼?因爲這確實是一個正確的解決方案。這可能會被標記爲重複。 – sevenseacat
你的寶石'i18n'版本是什麼? –
@RajeshCO i18n-0.6.9 – Eva