0

Heroku アカウントで作成した MongoHQ データベースに接続するように、MongoMapper を使用して Rails3 アプリケーションを構成しようとしています。現在、コードを Heroku にプッシュすると、Mongo::AuthenticationError でクラッシュします。ログからのスタック トレースは以下のとおりです。

TLDR /app/vendor/bundle/ruby/1.9.1/gems/mongo-1.9.2/lib/mongo/db.rb:175:in `issue_authentication': Failed to authenticate user 'heroku' on db 'app19340960' (Mongo::AuthenticationError)

これが完全なものです

Nov 11 22:55:03 qwikstubs heroku/web.1:  Starting process with command `bundle exec rails server -p 16121`
Nov 11 22:55:06 qwikstubs app/web.1:  => Booting Thin
Nov 11 22:55:06 qwikstubs app/web.1:  => Rails 3.2.11 application starting in production on http://0.0.0.0:16121
Nov 11 22:55:06 qwikstubs app/web.1:  => Call with -d to detach
Nov 11 22:55:06 qwikstubs app/web.1:  => Ctrl-C to shutdown server
Nov 11 22:55:07 qwikstubs app/web.1:  Exiting
Nov 11 22:55:07 qwikstubs app/web.1:  /app/vendor/bundle/ruby/1.9.1/gems/mongo-1.9.2/lib/mongo/db.rb:175:in `issue_authentication': Failed to authenticate user 'heroku' on db 'app19340960' (Mongo::AuthenticationError)
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/mongo-1.9.2/lib/mongo/db.rb:147:in `authenticate'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/connection.rb:83:in `connect'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/connection.rb:89:in `setup'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/railtie.rb:28:in `block in <class:Railtie>'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/config/environment.rb:5:in `<top (required)>'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/config.ru:3:in `require'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/config.ru:3:in `block in <main>'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/config.ru:in `new'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/config.ru:in `<main>'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
Nov 11 22:55:07 qwikstubs app/web.1:        from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
Nov 11 22:55:07 qwikstubs app/web.1:        from script/rails:6:in `require'
Nov 11 22:55:07 qwikstubs app/web.1:        from script/rails:6:in `<main>'
Nov 11 22:55:08 qwikstubs heroku/web.1:  Process exited with status 1

私の問題は、MongoMapper 接続を作成しようとする初期化ファイルに関係していると思います。コードは次のとおりです。ここにもあります

db_config = YAML::load(File.read(Rails.root.to_s + "/config/database.yml"))

if db_config[Rails.env] && db_config[Rails.env]['adapter'] == 'mongodb'
  mongo = db_config[Rails.env]
  MongoMapper.connection = Mongo::Connection.new(mongo['hostname'])
  MongoMapper.database = mongo['database']
end

新しい MongoMapper 接続を定義する行に何か問題があると確信しています。ロード元の database.yml ファイルは次のとおりです。

defaults: &defaults
  host: 127.0.0.1
  port: 27017
  adapter: mongodb

development:
  <<: *defaults
  database: qwikstubs-dev

test: 
  <<: *defaults
  database: qwikstubs-test

production:
  <<: *defaults
  uri: <%= ENV['MONGOHQ_URL'] %>
  database: qwikstubs
  username: <%= ENV['MONGO_USERNAME'] %>
  password: <%= ENV['MONGO_PASSWORD'] %>

これがおそらく単純な解決策であることはわかっていますが、ここで 2 つと 2 つを組み合わせる方法がよくわかりません。MongoHQ アプリケーションを使用したい場合、何を変更する必要がありますか? その初期化ファイルは、Heroku と MongoHQ を使用しても必要ですか?

どんな助けでも大歓迎です!

4

1 に答える 1