尝试生成mongoid.yml失败b / c database.yml中指定的适配器不存在gem

时间:2016-09-08 02:25:39

标签: ruby-on-rails ruby orm mongoid

我试图生成mongoid.yml文件并收到以下错误。我删除了database.yml。我怎样才能解决这个错误?

$ rails g mongoid:config            
/Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/application/configuration.rb:143:in `database_configuration': Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/railtie.rb:122:in `block (2 levels) in <class:Railtie>'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/base.rb:324:in `<module:ActiveRecord>'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/base.rb:24:in `<top (required)>'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:338:in `active_record_configured?'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:259:in `disconnect_database'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:97:in `preload'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:143:in `serve'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
    from /Users/tomcaflisch/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/tomcaflisch/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/tomcaflisch/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

1 个答案:

答案 0 :(得分:2)

config/application.rb删除以下内容:

require 'rails/all'

以下内容:

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"

这会禁用加载active_record

然后,您还需要在config.active_record.*目录下的所有文件中删除或注释掉所有config个文件,其中包括config/application.rbconfig/environments/*下的所有环境文件},所有初始值设定项位于config/initializers/

之下

最后,您还需要删除基于app/models的{​​{1}}目录下的所有模型。