There are a few documents
in Rails website and MongoDb website. Unfortunately they are out of date.
Recently I’ve set up a new Rails project with MongoDb. I’ve used following
steps:
- Install MongoDb http://www.mongodb.org/display/DOCS/Quickstart
- Install all MogoDb related Gems http://www.mongodb.org/display/DOCS/Ruby+Language+Center
- install MongoMapper http://mongomapper.com/
- Either Create new Rails project using the
template
o
rails project_name -m "http://gist.github.com/219223.txt"
- Or configure your project to use MongoDb instead of
default active record. This is an update of earlier post in MongoDb
website( http://www.mongodb.org/display/DOCS/Rails+-+Getting+Started)
o Save the following to config/database.rb file
MongoMapper.database
= "db_name-#{Rails.env}"
Replace
the db_name with your database name.
o Remove everything from config/database.yml file. This file should be empty.
o In config/application.rb
file replace
require 'rails/all' with following four require statements.
require
"action_controller/railtie"
require
"action_mailer/railtie"
require
"active_resource/railtie"
require
"rails/test_unit/railtie"
o In config/application.rb
file , in the Application class add following line
config.gem 'mongo_mapper'
o From environments/development.rb , environments/production.rb and environments/test.rb file remove all reference
to active_record
o Add following entries to the gemfile
gem
'bson_ext'
gem
'mongo_mapper'
o From test/test_helper.rb
file remove
fixtures
:all
No comments:
Post a Comment