将mongoid 4.0.1升级到5.1.0后出错

时间:2016-03-30 02:28:06

标签: ruby-on-rails mongoid

我升级了Mongoid,当我运行服务器时,出现以下错误。事实上,当我运行像控制台这样的东西时,我得到了同样的错误:

/Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:49:in `<class:Railtie>': uninitialized constant Mongoid::Config (NameError)
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:12:in `<module:Mongoid>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:7:in `<module:Rails>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/mongoid-5.1.1/lib/mongoid/railtie.rb:6:in `<top (required)>'
from /Users/SupremeA/rails-dev-box/code/True_Numbers/config/application.rb:5:in `require'
from /Users/SupremeA/rails-dev-box/code/True_Numbers/config/application.rb:5:in `<top (required)>'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:43:in `require'
from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

这对Railties来说似乎有问题,但我似乎无法看到如何修复它。

application.rb中

require File.expand_path('../boot', __FILE__)

require "action_controller/railtie"
require "action_mailer/railtie"
require "mongoid/railtie"
#require "active_resource/railtie" # Comment this line for Rails 4.0+
require "rails/test_unit/railtie"
require "sprockets/railtie" # Uncomment this line for Rails 3.1+

#require 'rails/all'
#config.filter_parameters += [:password, :password_confirmation]
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module AppName
  class Application < Rails::Application
    Mongoid.logger.level = Logger::DEBUG
    Moped.logger.level = Logger::DEBUG
    #load vendor files
    # 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
  end
end

- UPDATE -

从application.rb

中删除railties行后出现新错误

.../AppName/config/application.rb:19:in `<class:Application>': uninitialized constant AppName::Application::Moped (NameError) from /Users/SupremeA/rails-dev-box/code/AppName/config/application.rb:17:in `<module:AppName>' from /Users/SupremeA/rails-dev-box/code/AppName/config/application.rb:16:in `<top (required)>' from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:74:in `require' from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:74:in `block in <top (required)>' from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:71:in `tap' from /Users/SupremeA/.rvm/gems/ruby-2.2.1/gems/railties-4.0.10/lib/rails/commands.rb:71:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>'

1 个答案:

答案 0 :(得分:2)

我认为你的application.rb

中不需要这一行
require "mongoid/railtie"

只需删除它就可以了。

也删除此行:

Moped.logger.level = Logger::DEBUG

根据mongoid文档,如果你想编辑logger配置,请使用:

Mongoid.logger.level = Logger::DEBUG
Mongo::Logger.logger.level = Logger::DEBUG