2012-04-28 87 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 
相關問題