在流浪者的盒子上的Rails和Mongoid

时间:2013-11-12 03:35:48

标签: mongodb ruby-on-rails-4 mongoid vagrant

我有一个带有导轨4的流浪盒,最新版本的mongodb和mongoid。一旦流浪盒出现了,我就可以使用mongo来攻击mongodb,我可以访问mongodb和任何现有的数据库。问题似乎是我的rails代码没有写入mongodb。还有其他人经历过这个吗?是否存在我没​​有看到的配置问题?我应该运行哪些测试以便我可以获得一些错误来帮助调试此问题?

谢谢!

编辑:好的,重新启动网络服务器后,它似乎现在正常工作。或者至少我可以尝试通过rails console查询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:拼写

任何见解都会非常有用。谢谢!

1 个答案:

答案 0 :(得分:0)

配置文件中有拼写错误。第三行:

defualt:

应该是:

default: