在Windows上使用ROR和MongoDB

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介:          Ruby和MongoDB在Linux上结合非常自然,开发起来十分方便快捷,而在Windows上却稍微有些麻烦。         ROR默认使用ActiveRecord进行数据库操作,而如果要使用MongoDB代替MySQL或者SQLite,就要禁用ActiveRecord。

         Ruby和MongoDB在Linux上结合非常自然,开发起来十分方便快捷,而在Windows上却稍微有些麻烦。

         ROR默认使用ActiveRecord进行数据库操作,而如果要使用MongoDB代替MySQL或者SQLite,就要禁用ActiveRecord。那么创建新项目的命令就是:

rails new watermelon --skip-active-record

项目创建后,进入config目录,可以看到里面并没有database.yml文件。接着编辑Gemfile,添加下面两行内容:

source 'http://gemcutter.org'

gem 'mongo_mapper'

然后运行

bundle install

会安装:bson 1.3.1,mongo 1.3.1,plucky 0.3.8和mongo_mapper 0.9.1。除了这些之外,还需要bson_ext,于是就想通过

gem install bson_ext

进行安装,可是得到了下面的错误信息:

         从提示信息中可以看出需要安装一个开发工具包。步骤如下:

         1. 在RubyInstaller for Windows的下载页面上http://rubyinstaller.org/downloads找到DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe,直接点击下载;

         2. 下载完成后,双击解压到某个目录下,例如:C:/work/tools/DevKit

         3. 在命令行窗口下进入到C:/work/tools/DevKit目录下,运行

ruby dk.rb init
在C:/work/tools/DevKit下会产生一个config.yml文件,

         4. 编辑config.yml文件,初始内容类似:

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
在其中加入Ruby的安装目录,如:

---
- C:/work/tools/Ruby192

      5. 运行

ruby dk.rb install
相应的文件就安装C:/work/tools/Ruby192/lib/ruby/site_ruby下面。

     经过上面几步就完成了DevKit的安装,然后就可以通过

gem install bson_ext --platform=ruby

安装bson_ext。

      环境配置完成后,就可以进入ROR和MongoDB相结合的开发了。


      参考资料:

      MongoDB Ruby Driver Tutorial

      MongoDB  Ruby Language Center Rails3 - Getting - Started

      Ruby Installer Development Kit


目录
相关文章
|
5月前
|
NoSQL IDE MongoDB
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
348 3
|
2月前
|
NoSQL IDE MongoDB
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
257 1
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
5月前
|
NoSQL IDE MongoDB
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
435 21
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
8月前
|
NoSQL IDE MongoDB
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
322 2
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
8月前
|
NoSQL IDE MongoDB
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
318 0
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
存储 NoSQL MongoDB
MongoDB入门级别教程全(Windows版,保姆级教程)
一份全面的MongoDB入门级教程,包括在Windows系统上安装MongoDB、使用MongoDB Shell和Compass GUI进行数据库操作,以及MongoDB的基本数据类型和查询技巧。
2838 2
MongoDB入门级别教程全(Windows版,保姆级教程)
|
NoSQL Shell MongoDB
Windows 平台安装 MongoDB
10月更文挑战第10天
383 0
Windows 平台安装 MongoDB
|
28天前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
364 2
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
|
28天前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
179 0
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
|
28天前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
325 0

热门文章

最新文章

推荐镜像

更多