rails3 使用 mongoid的步骤
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.$railsgmongoid: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
相关推荐
lei0 2020-11-02
webgm 2020-08-16
igogo00 2020-07-04
iconhot 2020-06-26
88481456 2020-06-18
疯狂紫萧 2020-06-16
yezitoo 2020-06-06
SelinaChan 2020-05-15
luckymaoyy 2020-04-25
80437700 2020-04-17
austindev 2020-04-07
我有一只小松鼠 2020-02-29
webfullStack 2020-02-15
binglingnew 2012-10-03
始作俑者 2020-01-19
jinxiutong 2020-01-04
Dawnworld 2019-12-23
yezitoo 2019-12-05