首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mongoid.yml在哪?

mongoid.yml在哪?
EN

Stack Overflow用户
提问于 2013-05-28 20:30:06
回答 1查看 1.2K关注 0票数 2

我刚安装了mongoid。我尝试了他们的示例代码,它引发了一个漂亮的错误,并建议“仔细检查您的mongid.yml...”所以我在mongoid.org,where they say上阅读了他们的介绍:"Mongoid配置可以通过mongoid.yml完成“。但我明白,每个人都理所当然地认为,像我这样的菜鸟会知道mongoid.yml在哪里。当然,我可以只使用find -name mongoid.yml,但这不是很奇怪吗?这是每个新的Mongoid用户都要经历的一种痛苦吗?

编辑:好的,这就是我从Mongoid网站上看到的。

代码语言:javascript
复制
require 'mongoid'

class Human
  include Mongoid::Document
  field :name, type: String
  embeds_many :interests
end

class Interest
  include Mongoid::Document
  field :content, type: String
  embedded_in :human
end

ccfu = Human.where( name: "John Doe" )
ccfu.interests.create( content: "criminal activity" )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-28 20:36:58

如果你没有使用Ruby on Rails,你可以把mongoid.yml放在你喜欢的任何地方,然后在你的代码中,你可以使用load!方法加载它:

代码语言:javascript
复制
Mongoid.load!('path/to/mongoid.yml', :development)

或者:

代码语言:javascript
复制
ENV['MONGOID_ENV'] = 'development'
Mongoid.load!('path/to/mongoid.yml')

在Ruby On Rails上,它位于config目录中。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16792131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档