William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

A rails+mongo Gemfile sample

A rails+mong Gemfile sample

While I learn Rails, I found a good sample to combine MongoDB into Rails, I list here for quick retrieving:

source 'https://rubygems.org'
require 'mongo'

gem 'rails', '3.2.12'
gem 'bootstrap-sass', '2.1'

group :development, :test do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  gem 'mongo_mapper', '~> 0.12.0'
  gem 'bson_ext', '~> 1.8.2'
  gem 'bson', '~> 1.8.2'
  gem 'mongo', '~> 1.8.2'

  gem 'uglifier', '>= 1.0.3'

  gem "rspec-rails", "~> 2.0"

gem 'jquery-rails'

Of course, need to install (probably need root permission):

$ bundle install

After successfully install, I created a config file: #{app}/config/initializers/mongo_config.rb to initialize it:

MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "test"
if defined?(PhusionPassenger)
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
  MongoMapper.connection.connect if forked

After the config, right now when Webrick starts, the MongoDB is associated to connect.


2 responses to “A rails+mongo Gemfile sample

  1. williamjxj 07/08/2013 at 3:48 pm

    This is a comment from worldpress.

  2. williamjxj 07/08/2013 at 3:49 pm

    This is another comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: