好的,所以我有一个新的rails应用程序,我在ec2上的ubuntu 11.10,它有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正在运行但是这个错误令人困惑
答案 0 :(得分:1)
如果要使用空白config / database.yml运行或删除它,则必须删除对Active Record的所有引用。下面的工作对我来说,检查它的config / application.rb以及我必须做些什么来获得一个新的Rails项目来传递你提供的Gemfile和config / mongoid.yml的初始测试。请注意,您还应该在test / test_helper.rb中注释掉“fixture: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