Thursday, 3 November 2011

supporting links for mongoDB

Getting started:

For mongo shell:

Getting MongoDB and Devise to play well on Rails 3


Wednesday, 2 November 2011

Rails application using mongomapper (mongoDB)

1) Edit Gemfile, located in the Rails root directory. By default, our Gemfile will only load Rails:

                      require 'mongo'

         gem "mongo_mapper"
         gem "bson_ext"

2) Once you've configured your Gemfile, run the bundle installer:
          bundle install

3) Last item is to create an initializer to connect to MongoDB. Create a Ruby file in config/initializers.       You can give it any name you want; here we'll call it config/initializers/mongo.rb:

MongoMapper.connection ='localhost', 27017)
   MongoMapper.database = "#myapp-#{Rails.env}"

   if defined?(PhusionPassenger)
       PhusionPassenger.on_event(:starting_worker_process) do |forked|
       MongoMapper.connection.connect if forked
4) Create a model with mongomapper
 class User 
  include MongoMapper::Document
   key :name,  String
   key :email, String
   validates_presence_of :name, :email 
6)Generate the controller and view for the User model..