This document contains the steps to create a mongo-enabled Rails 3.1 application. This is just for personal reference actually.
We have to skip the Active Record stuff:
rails new app_name --skip-active-record
We are using mongo_mapper
... though mongoid looks good to. So, we have to add the mongo_mapper
gem and the bson_ext
for performance:
gem 'mongo_mapper'
gem 'bson_ext'
Then run bundle install
as usual.
First, let's create a configuration file by executing this command:
rails generate mongo_mapper:config
Command above will create a config/mongo.yml
file. That's it... just awesome!
Create a Procfile
like this:
mongo: mongod
rails: rails server
Then just use the foreman start
command to start both services.
It is important to create the Heroku app in the Cedar stack. Not sure why it does not work on the Bamboo one. So you must use:
heroku create --stack cedar app-name
To create a MongoLabs account:
heroku addons:add mongolab:starter
Then, just use the following command to get the connection Uri:
heroku config | grep MONGOLAB_URI
Using the Uri information you must edit the config/mongo.yml
file in the production section. For more information or steps to create/restore backups refer to the official documentation.
If using HAML, add haml-rails
gem to your Gemfile
:
gem 'haml-rails'
And add this to the config/application.rb
file:
config.generators do |g|
g.template_engine :haml
end
Here you just have to specify the ORM to use (shouldn't be ODM? whatever):
rails generate scaffold model_name name:string --orm=mongo_mapper
rails generate mongo_mapper:model model_name field:type field:type