Catfish Catfish - 2 months ago 23
Ruby Question

Trying to generate mongoid.yml fails b/c no gem exists for specified adapter in database.yml

I'm trying to generate the mongoid.yml file and receiving the error below. I've deleted database.yml. How can I get around this error?

$ 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>'

Answer

In your config/application.rb remove the following:

require 'rails/all'

with the following:

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"

This disables loading active_record.

Then you also need to remove or comment out all occurrences of config.active_record.* in config/application.rb and all the environment files located under config/environments/*.

And finally, you also need to remove all the models under app/models directory which are based off ApplicationRecord.

Comments