2中使用Mongoid时删除database

2中使用Mongoid时删除database

本文介绍了在Rails 3.2中使用Mongoid时删除database.yml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始一个新的Rails项目,并想通过Mongoid gem使用MongoidDB.按照Mongoid网站上的说明,我在Gemfile

I just began a new rails project and wanted to use MongoidDB thru the Mongoid gem. Following the instructions on the Mongoid site, I added the following lines to my Gemfile:

gem "mongoid", "~> 2.4"
gem "bson_ext", "~> 1.5"

然后我按照此处中的说明删除我的database.yml文件.我的application.rb文件现在看起来像这样:

I then proceeded to removing my database.yml file as per the instructions here. My application.rb file now looks like so:

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

现在,当我使用rails s来启动开发中的服务器时,出现以下错误:

Now, when I use rails s to start my server in development, I get the following errors:

~/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `active_record' for #<Rails::Application::Configuration:0x007ff38b20d0b0> (NoMethodError)

我试图寻找一种解决方案,但似乎还没有人遇到我的问题.难道我做错了什么?这是由最近的Rails 3.2更新引起的吗?

I tried looking for a solution, but it seems no one has yet to come across my problem. Am I doing something wrong? Is this caused by the recent Rails 3.2 update?

感谢您的帮助!

更新(1月26日):根据Dylan Markow提供的信息,我使用了终端命令

UPDATE (Jan 26):Based on the info from Dylan Markow, I used the terminal command

grep -r active_record config/

然后将所有引用都放在注释块中的active_record中.

And put any refrences to active_record in comment blocks.

我有一个简单的控制器,它的一个动作甚至还没有击中数据库.通过浏览器访问操作时,我会得到

I have a simple controller with one action that does not even hit the database yet. When I access the action via browser I get

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
  activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
  activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
  activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
  activerecord (3.2.0) lib/active_record/query_cache.rb:67:in `rescue in call'
  activerecord (3.2.0) lib/active_record/query_cache.rb:61:in `call'
  activerecord (3.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `_run__186077810047649794__call__2115495702768811851__callbacks'
  activesupport (3.2.0) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.0) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.0) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.0) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.0) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.0) lib/rails/engine.rb:479:in `call'
  railties (3.2.0) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.0) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/aren/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/aren/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/aren/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'


  Rendered /Users/aren/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.8ms)
  Rendered /Users/aren/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (39.4ms)
  Rendered /Users/aren/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (54.0ms)

如何解决以上问题?为什么什至试图建立ActiveRecord数据库连接?

How do I fix the above issue? Why is an ActiveRecord database connection even trying to be established?

再次感谢!

推荐答案

也许注释这两行

config/environments/development.rb:

# config.active_record.mass_assignment_sanitizer = :strict
# config.active_record.auto_explain_threshold_in_seconds = 0.5

这篇关于在Rails 3.2中使用Mongoid时删除database.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:43