0

好的,所以我在 ec2 上的 ubuntu 11.10 上有一个新的 rails 应用程序,它有 mongoid 作为数据库,我一直收到这个错误

ActionView::Template::Error (db_name must be a string or symbol):

这是我的 config/mongoid.yml

development:
  host: localhost
  database: mm_development

test:
  host: localhost
  database: mm_test

# set these environment variables on your prod server
production:
  host: <%= ENV['MONGOID_HOST'] %>
  port: <%= ENV['MONGOID_PORT'] %>
  username: <%= ENV['MONGOID_USERNAME'] %>
  password: <%= ENV['MONGOID_PASSWORD'] %>
  database: <%= ENV['MONGOID_DATABASE'] %>
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019

我的 database.yml 是空白的,因为我不知道如果有什么需要去那里。这是我的 mongoid 的 gemfile

gem 'rails', '3.2.3'
gem 'jquery-rails'
gem 'haml'
gem 'unicorn'
gem 'mongoid'

首先我想知道是否有人知道我需要对 database.yml 做什么,然后我该如何解决这个问题....mongo 已启动并正在运行,但这个错误令人困惑

4

1 回答 1

1

如果要使用空白 config/database.yml 运行或删除它,则必须删除对 Active Record 的所有引用。以下对我有用,检查它的 config/application.rb 以及我必须做些什么才能让一个新的 Rails 项目通过您提供的 Gemfile 和 config/mongoid.yml 的初始测试。请注意,您还应该在 test/test_helper.rb 中注释掉“fixtures :all”。我建议您重新创建以下等效项作为开始的干净基础。希望这会有所帮助。

$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
$ rails _3.2.3_ new free-11137-db_name
$ cd free-11137-db_name

Gemfile as per user

$ bundle install
$ gem install unicorn
$ bundle install
Using mongo (1.6.2)
Using mongoid (2.4.8)

$ rails g mongoid:config

config/mongoid.yml as per user
config/database.yml blank as per user
config/application.rb
    #require 'rails/all'
    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+

remove all references to Active Record as follows
    config/application.rb
        #config.active_record.whitelist_attributes = true

    config/environments/development.rb
        #config.active_record.mass_assignment_sanitizer = :strict
        #config.active_record.auto_explain_threshold_in_seconds = 0.5

    config/environments/test.rb
      #config.active_record.mass_assignment_sanitizer = :strict

    test/test_helper.rb
        #fixtures :all

$ rails g model person
$ cat app/models/person.rb
class Person
  include Mongoid::Document
end
$ rm test/fixtures/people.yml
$ bundle exec rake test # succeeds
$ rm config/database.yml
$ bundle exec rake test # succeeds
于 2012-05-01T16:44:42.573 回答