簡體   English   中英

無家可歸的盒子上的Rails和Mongoid

[英]Rails and Mongoid on a Vagrant Box

我有一個設置了rails 4(最新版本的mongodb和mongoid)的無聊的盒子。 一旦出現了無用信息框,我就可以使用mongo命中mongodb,並且可以訪問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.

按照“解決方案”的建議,我在config/mongoid.yml下進行了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:拼寫

任何見解將非常有幫助。 謝謝!

配置文件中有一個錯字。 第三行:

defualt:

應該:

default:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM