日期:2014-05-16 浏览次数:20458 次
rails new spec_mongoid
gem "mongoid" gem "bson_ext"
$ rails g mongoid:config
create config/mongoid.yml
gem 'execjs' gem 'therubyracer'
# require 'rails/all'
require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "rails/test_unit/railtie"
# config.active_record.mass_assignment_sanitizer = :strict # config.active_record.auto_explain_threshold_in_seconds = 0.5
Mongoid.load!("path/to/your/mongoid.yml")
config.mongoid.logger = Logger.new($stdout, :warn)
logger: false
Mongoid.add_language("zh-CN")
Mongoid.add_language("*")
host is not a valid option for Mongo::Connection
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
undefined method `add_language' for Mongoid:Module (NoMethodError)
#Mongoid.add_language("*")注释掉
$ rails g model user invoke mongoid create app/models/user.rb invoke test_unit create test/unit/user_test.rb create test/fixtures/users.yml
class User include Mongoid::Document end
ruby-1.9.2-p180 :003 > User.create(:name=>"李磊") => #<User _id: 4f630bf1421aa97127000001, _type: nil, name: "李磊", login: nil, age: nil> ruby-1.9.2-p180 :002 > user = User.find('4f630bf1421aa97127000001') => #<User _id: 4f630bf1421aa97127000001, _type: nil, name: "李磊", login: nil, age: nil> ruby-1.9.2-p180 :004 > user.update_attributes(:name=>"李磊",:login=>"lilei",:age=>15) => true ruby-1.9.2-p180 :005 > user => #<User _id: 4f630bf1421aa97127000001, _type: nil, name: "李磊", login: "lilei", age: 15>
# fixtures :all
# encoding: utf-8 require 'test_helper' class UserTest <