2012-08-13 45 views
5

我正在致力於a simple app,目前部署到heroku - 它使用mongoid,設備,並且可以非常容易地在localhost中創建用戶登錄,但不能在生產中Heroku的。您可以嘗試創建一個帳戶,並在提交後出現錯誤。MongoidDB,Heroku,設備,MongoHQ和Rails的MongoDB錯誤

我認爲我的生產mongoid.yml需要改變,但我不知道如何。

heroku config有以下幾點:

=== Config Vars for bookfoo 
DATABASE_URL:  postgres://jeibucpexp:[email protected]/jeibucpexp 
GEM_PATH:   vendor/bundle/ruby/1.9.1 
LANG:    en_US.UTF-8 
MONGOHQ_URL:   mongodb://heroku:[email protected]:10065/app6153931 
MONGOLAB_URI:  mongodb://heroku_app6153931:[email protected]:37097/heroku_app6153931 
PATH:    bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin 
RACK_ENV:   production 
RAILS_ENV:   production 
SHARED_DATABASE_URL: postgres://jeibucpexp:[email protected]/jeibucpexp 

mongoid.yml具有的建議在Heroku的以下內容:

development: 
    sessions: 
    default: 
     database: bookfoo_app_development 
     hosts: 
     - localhost:27017 
     options: 
     consistency: :strong 
    options: 
test: 
    sessions: 
    default: 
     database: bookfoo_app_test 
     hosts: 
     - localhost:27017 
     options: 
     consistency: :strong 
production: 
    sessions: 
    default: 
     uri: <%= ENV['MONGOHQ_URL'] %> 
    options: 
     skip_version_check: true 
     safe: true 

我的Gemfile有以下幾點:

source 'https://rubygems.org' 

gem 'rails', '3.2.3' 

group :development, :test do 
    gem 'sqlite3' 
    gem 'rspec-rails' 
end 

group :test do 
    gem 'database_cleaner' 
    gem 'mongoid-rspec' 
    gem 'factory_girl_rails' 
    gem 'email_spec' 
    gem 'capybara' 
    gem 'launchy' 
end 

group :production do 
    gem 'thin' 
end 

group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 
gem "mongoid", :git => "git://github.com/mongoid/mongoid.git" 
gem "bson_ext" 
gem "devise" 

git push heroku master後它給了我以下提示:

There is a configuration error with the current mongoid.yml. 
     Problem: 
     No database provided for session configuration: :options. 
     Summary: 
     Each session configuration must provide a database so Mongoid knows where the default database to persist to. What was provided was: {"skip_version_check"=>true, "safe"=>true}. 
     Resolution: 
     If configuring via a mongoid.yml, ensure that within your :options section a :database value for the session's default database is defined. 
     Example: 
     \_\_development: 
     \_\_\_\_sessions: 
     \_\_\_\_\_\_options: 
     \_\_\_\_\_\_\_\_database: my_app_db 
     \_\_\_\_\_\_\_\_hosts: 
     \_\_\_\_\_\_\_\_\_\_- localhost:27017 

回答

5

mongoid.yml應該是這樣(我的縮進是錯誤的):

production: 
    sessions: 
    default: 
     uri: <%= ENV['MONGOHQ_URL'] %> 
     options: 
     skip_version_check: true 
     safe: true 
+0

感謝。我已經找了幾個小時,然後我意識到這是縮進:/ – macool 2015-10-06 17:24:43