2011-05-11 82 views
2

我最近分叉了https://github.com/fortuity/rails3-mongoid-omniauth并试图在heroku.com上运行。这是一个应用程序,演示如何在heroku上使用MongoDB(通过MongoHQ)以及OAuth身份验证。我分叉的代码快照是https://github.com/jgodse/rails3-mongoid-omniauth/tree/8cb490e660ab1d2d1df0f68312584563f0fd223aHeroku:MongoHQ:连接问题

当我调整了mongoid.yml以包含URI参数后,删除其他参数为生产(即heroku)环境,然后在heroku.com上启动应用程序,我得到以下日志来自heroku日志)。

←[36m2011-05-11T19:00:36+00:00 heroku[web.1]:←[0m Starting process with command: thin -p 41913 -e production -R /home/heroku_rack/heroku.ru start 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:494:in connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure) 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:632:insetup' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:101:in initialize' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:152:innew' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:152:in from_uri' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config/database.rb:86:inmaster' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config/database.rb:19:in configure' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config.rb:319:inconfigure_databases' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config.rb:114:in from_hash' 
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from (eval):2:infrom_hash' 
←[36m2011-05-11T19:00:42+00:00 heroku[web.1]:←[0m Process exited 
←[36m2011-05-11T12:00:43-07:00 heroku[web.1]:←[0m State changed from starting to crashed 

我的Heroku的环境看起来像这样(有一些关键的信息xxxx'ed出):

$ heroku info 
=== jgodse-omniauth-mongoid 
Web URL: http://jgodse-omniauth-mongoid.heroku.com/ 
Git Repo: [email protected]:jgodse-omniauth-mongoid.git 
Dynos: 1 
Workers: 0 
Repo size: 5M 
Slug size: 5M 
Stack: bamboo-mri-1.9.2 
Data size: (empty) 
Addons: Basic Logging, MongoHQ MongoHQ Free, Shared Database 5MB 
Owner: xxxxxxxx 

[email protected] ~/rapps/rails3-mongoid-omniauth (master) 
$ heroku config --long 
BUNDLE_WITHOUT => development:test 
DATABASE_URL => postgres://xxxxxxxxxxxx 
LANG => en_US.UTF-8 
MONGOHQ_URL => mongodb://heroku:xxxxxxxxxxxxxxxxxxxxxxxxxxxx.mongohq.com:27098/app527030 
RACK_ENV => production 
SHARED_DATABASE_URL => postgres://xxxxxxx xxxxxx 

Heroku的日志说,它仍在试图连接到本地主机:27017即使我删除本地主机引用从mongoid.yml。还有什么我必须做的强制它连接到我的MONGOHQ_URL?

回答

2

在文件mongoid.yml中,我应该使用“MONGOHQ_URL”,但我使用了“MONGHQ_URL”。因此,代码的行为与本应该默认的一样,默认为localhost。

当我在mongoid.yml中开始使用“MONGOHQ_URL”时,一切正常。