使用 MongoDB 创建多个 Rails 应用程序时出现问题
我正确安装了 MongoDB 并让它在我的 OSX 上运行。我使用 MongDB 和 Rails3 创建的第一个应用程序的标题是“todo”。 关于railscasts的说明,我创建了一个文件(config/initializers/ mongo.rb)并添加了这一行:
MongoMapper.database = "todo-
#{Rails.env}"
据推测,这创建了出现在我的 /data/db/ 文件中的文件,标题为“todo- 当我在Rails中使用generate命令来创建 模型,数据已正确存储在该文件中。一切顺利,到此为止 观点。
现在的问题是,我似乎无法在 /data/db 文件中创建新文件 我使用 Rails 创建新应用程序。 (我认为)数据文件应该是 从初始化文件创建(例如:
MongoMapper.database = "newproject-
#{Rails.env}"
我添加到每个新应用程序中。但是它 不是。
这是我的 gemfIle (与我的第一个应用程序一起使用!:
require 'rubygems'
gem 'mongo', '1.0'
source 'http://gemcutter.org'
gem 'rails', '3.0.0.beta4'
gem "mongo_mapper"
gem 'bson_ext', '1.0'
任何帮助将不胜感激!
I properly installed MongoDB and got it running on my OSX. The first app I created using MongDB and Rails3 was titled 'todo". Per the
instructions on railscasts, I created a file (config/initilializers/
mongo.rb) and added this line:
MongoMapper.database = "todo-
#{Rails.env}"
Presumably, this created the files that appeared in my /data/db/ file entitled "todo-
development". When I used the generate command in Rails to create the
models, the data was correctly stored in this file. All good, up to this
point.
The problem now is that I can't seem to create NEW files in the /data/db file when
I create new apps with Rails. (I think) the data file should be
created from the initializer file (ex:
MongoMapper.database = "newproject-
#{Rails.env}"
that I add to each new app. But it
is not.
Here's my gemfIle (that worked with my first app!:
require 'rubygems'
gem 'mongo', '1.0'
source 'http://gemcutter.org'
gem 'rails', '3.0.0.beta4'
gem "mongo_mapper"
gem 'bson_ext', '1.0'
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终在 Google 群组中的克里斯蒂安·曼德鲁普 (Kristian Mandrup) 的帮助下解决了这个问题。谢谢克里斯蒂安。我需要取消 application.rb 文件中 config.generator 的注释,并将 orm 从 active_record 更改为 mongo_mapper。 (顺便说一句,我之前尝试运行生成器时遇到的错误是“没有为所需选项'--orm'提供值。”)
更多信息请参见:http://www.viget.com/extend/rails-3-generators-hooks/
对于它的价值,我包括让 MongoDB 和 Rails 3 正常协同工作所需的整个过程。
在 OSX 上安装 MongoDB
创建数据目录:
设置数据目录的权限:
在终端中启动 Mongo:
访问本地主机以验证 MongoDB 是否正在运行。 :
使用 Rails 3 创建新项目:
将其添加到 gemfile:
取消注释(并修改)application.rb 文件中的这些行:
创建 config/initializer/mongo.rb 文件:
创建 lib/tasks/mongo.rake 文件:
安装gems:
创建第一个模型:
创建 models/product.rb 文件:
Finally figured this out with the help Kristian Mandrup in a Google Group. Thanks Kristian. I needed to uncomment the config.generator in my application.rb file and change orm from active_record to mongo_mapper. (btw, the error I was getting before when trying to run the generator was ""No value provided for required options '--orm'.")
More here: http://www.viget.com/extend/rails-3-generators-hooks/
For what it's worth, I'm including the entire process that I needed to take in order to get MongoDB and Rails 3 working together properly.
Install MongoDB on OSX
Create a data directory:
Set permissions for data directory:
Start Mongo in Terminal:
Visit local host to verify that MongoDB is running:
Create new project with Rails 3:
Add this to the gemfile:
uncomment out (and modify) these lines in application.rb file:
Create config/initializer/mongo.rb file:
Create a lib/tasks/mongo.rake file:
Install gems:
Create first model:
Create models/product.rb file: