This blog post lists step by step instructions for integrating MongoDB in RAILS Application .
STEP 1:
To create application with Mongo db you need to skip active record.
Type command
rails new app_name -–skip-active-recordSTEP 2: Before bundle install make sure that you have included following gems in your gemfile.
gem 'mongoid' gem 'bson_ext' run bundle intsallIF any problem occurs during bundle installation remember dependencies of mongoid should be of same version.Otherwise it will give error while installing bundle. Now you can see that dependencies of gem 'mongoid' are of same version in snapshot. gem 'mongo' '1.6' gem 'bson' '1.6' gem 'bson_ext' '1.6' STEP 3: Now run the server check whether connection established with mongoid. Mongoid.yml is not found. STEP 4: Let's create mongoid.yml file .
rails g mongoid:configSTEP 5: Let's generate scaffold,here we dont need to mention skip active record though it is already mentioned. Type command
rails g scaffold article name:string content:textWhen you will check your model you will find instead of
class Article<ActiveRecord::Base end class Article include Mongoid::Document endNow instead of generating migration we will write fields in model itself.
class Article include Mongoid::Document field :name,:type => String endNo need of migration file in mongo db. Now Start the Server . STEP 5: Validation and Association Validation is same as it was in ActiveRecord but Associations is slightly different.Some new association are introduced.
embeds_many and embedded_in,embeds_one and embedded_in,references_many and referenced_in,references_one and referenced_in and associations used in active record.Post Comments And Suggestions !!! Thanks to Santosh for writing this post .