mongodb 官方的文档 (
http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started) 是专门为 "mongomapper" 准备的。不适用于 "mongoid",所以,大家不要看了。
参考mongoid的官方文档:
http://mongoid.org/
1. 在 Gemfile中增加:
gem "mongoid", "~> 2.4"
gem "bson_ext", "~> 1.5"
2. $ rails g mongoid:config
会生成 config/mongoid.yml , 形如:
development:
host: localhost
database: miaomiao_cat_development
test:
host: localhost
database: miaomiao_cat_test
# set these environment variables on your prod server
production:
host: localhost
database: miaomiaocat_production
3. 编辑config/application.rb
删掉:
require 'rails/all'
增加:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# require "sprockets/railtie" # Uncomment this line for Rails 3.1+
4. 把development.rb, test.rb 中,下面2行去掉:
引用
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
5. 去掉spec_helper.rb 中的:
引用
config.use_transactional_fixtures = true
(以下步骤就可以参考 mongoid 官方文档了)
6. 建立任意一个model . 注意这个 include
class Apple
include Mongoid::Document
#...
end
分享到:
相关推荐
MongoDB 是一个流行的开源文档数据库,它以JSON格式存储数据,并使用Mongoid作为其在Ruby on Rails框架中的ORM(对象关系映射)工具。在传统的SQL数据库中,我们可以使用自增主键来确保每条记录都有一个唯一的标识符...
在Rails应用中使用MongoDB,你需要以下步骤: 1. **安装驱动**:首先,你需要安装`mongodb`和`mongoid`或`mongo_mapper`驱动,这两个都是Ruby的MongoDB适配器。`mongoid`是更流行的选项,提供更全面的ORM(对象关系...
可验证(支持ActiveRecord和Mongoid) (支持Rails,Rails API和ActionController::Metal ) 如果您想进一步了解宝石的工作原理,请继续阅读! 概述之后,我们将执行以下两个步骤。总览简单令牌身份验证提供了从...
标题 "casino-sso-client-rails4-example" 提供了一个关于使用CASino(Central Authentication Service,中央认证服务)作为SSO(Single Sign-On,单点登录)服务器的Rails4应用程序客户端示例。这个项目旨在帮助...
3. **Mongoid ORM**:学习如何使用Mongoid与MongoDB数据库交互,存储和检索聊天记录数据。 4. **数据库管理**:理解NoSQL数据库MongoDB的基本概念和操作。 5. **命令行工具**:掌握在终端中运行Rails命令,如生成...
`will_paginate`的使用通常包括以下几个步骤: 1. **引入Gem**:首先,在Gemfile中添加`gem 'will_paginate'`,然后运行`bundle install`安装。 2. **配置数据库适配器**:根据你的数据库类型(如MySQL、...
使用 `will_paginate` 的步骤大致如下: 1. 首先,在 Gemfile 中添加 `gem 'will_paginate'`,然后运行 `bundle install` 安装插件。 2. 在模型(model)中,使用 `has_many :through` 或其他关联方法查询数据,...
泡菜 Pickle为您提供了Cucumber步骤,可以轻松地由工厂女孩,机械师或制造人员创建模型。 您也可以仅将ActiveRecord用作工厂,但它并不那么酷。 Pickle可以使用不同的ORM来查找记录。 当前提供了ActiveRecord,...
自述 此自述文件记录了启动和运行应用... 应用程序服务器使用 `rake bower:install` 获取客户端依赖项 使用 `rails server` 命令运行应用程序 如何运行测试套件 服务(作业队列、缓存服务器、搜索引擎等) 部署说明