Sunday, 19 February 2012

MongoDB with Rails Getting Started


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:
o    rails project_name -m "http://gist.github.com/219223.txt"
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