Uploading Rails App with MongoDB to Heroku


  1. Navigate to your git repository from your computer
  2. Open Gemfile then change gem ‘sqlite3’ to gem ‘pg’
  3. Run the command: “bundle install”
  4. Ensure the config/database.yml is using the postgresql adapter. by changing all “sqlite3” instance to “postgresql”
  5. At the end of Gemfile add:
    ruby “2.3.1”
    – or check version using ruby -v
  6. Login to your heroku account
    $ heroku login
  7. Create a project, CD to where your git project is located in your local computer then type in:
    $ heroku create
    – prepares Heroku to receive your source code.
  8. deploy your code by running the command:
    $ git push heroku master
  9. The application is now deployed. Ensure that at least one instance of the app is running:
    $ heroku ps:scale web=1
  10. Run the database migration:
    $ heroku run rake db:migrate
  11. Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:
    heroku open
  12. Do mongodb installation, see instructions bellow:

Installing mongodb Add-on

  1. Run the command: heroku addons:create mongolab:sandbox
  2. Run the command bellow to ensure we have MONGO_URI on our heroku config:
    $ heroku config
    It shows something like this:
    MONGODB_URI: mongodb://heroku_1c3dj371:6ncboo79ofhq5kg49ugiihe5th@ds035856.mlab.com:35856/heroku_1c3dj371
  3. Add production DB connection in your config/mongoid.yml:
                uri: <%= ENV['MONGODB_URI'] %>
                skip_version_check: true
            safe: true
  4. Commit and push your code to heroku.

To commit a code to Heroku

  • Almost every deploy to Heroku follows this same pattern. First, add the modified files to the local git repository:
    $ git add .
  • Now commit the changes to the repository:
    $ git commit -m “Demo”
  • Now deploy, just as you did previously:
    $ git push heroku master
  • Finally, check that everything is working:
    $ heroku open

Others Notes

  1. You can view information about your running app using one of the logging commands in real time using:
    $ heroku logs –tail
  2. If you changed the name of your heroku app from heroku website, you can
    perform the following command to update your local git project connection
    1. $ git remote rm heroku
    2. $ heroku git:remote -a NEW_NAME_OF_YOUR_APP

Do you need help with a project? or have a new project in mind that you need help with?

Contact Me