2012-04-28 61 views
0

好吧,我有一个新的Rails应用程序,我已经在ec2上的Ubuntu 11.10,它有mongoid作为分贝,我不断收到这个错误ActionView :: Template :: Error(db_name必须是一个字符串或符号):

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

这里是我的配置/ 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

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

第一的Gemfile我想知道是否有人知道我需要什么用的database.yml做,然后我如何解决这个问题....蒙戈启动并运行,但这个错误令人困惑

回答

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 
相关问题