0

mongodb と mongoid の最新バージョンである Rails 4 でセットアップされた vagrant box があります。vagrant ボックスが起動したら、mongodb を使用してヒットmongoでき、mongodb と既存のデータベースにアクセスできます。私の Rails コードが mongodb に書き込んでいないことが問題のようです。他の誰かがこれを経験しましたか?表示されていない構成上の問題はありますか? この問題のデバッグに役立つエラーを取得するには、どのテストを実行する必要がありますか?

ありがとう!

編集:ウェブサーバーを再起動すると、今は動作しているようです。または、少なくとも Rails コンソール経由で mongodb にクエリを実行できます。さらにテストを続けているので、更新します。

編集 2: したがって、Rails サンドボックス コンソールでは、User.all を使用して User コレクションを調べることができますが、User.first で次のようなエラーが表示されます。

Mongoid::Errors::NoSessionConfig:
Problem:
  No configuration could be found for a session named 'default'.
Summary:
  When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
  Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.

解決策の提案に従って、mongoid.yml を簡単にチェックしたところ、config/mongoid.ymlそのようにリストされていることがわかりました。

development:
  sessions:
    default:
      database: mongoid
      hosts:
        - localhost:21017
      options:
  options:
test:
  sessions:
    default:
      database: mongoid
      hosts:
        - localhost:21017
      options:
        consistency: :strong
        max_retries: 1
        retry_interval: 0

編集 3: この問題は、Rails コンソールをサンドボックス モードで実行しようとしたときにのみ発生するようです。通常の Rails コンソールでは問題なく動作します。とにかくサンドボックスコンソールで動作させるには?

編集 4: スペル

どんな洞察も非常に役に立ちます。ありがとう!

4

1 に答える 1

0

設定ファイルにタイプミスがあります。3 行目:

defualt:

次のようにする必要があります。

default:
于 2013-11-14T01:11:12.587 に答える