Uploading Rails App with MongoDB to Heroku
- Navigate to your git repository from your computer
- Open Gemfile then change gem ‘sqlite3’ to gem ‘pg’
- Run the command: “bundle install”
- Ensure the config/database.yml is using the postgresql adapter. by changing all “sqlite3” instance to “postgresql”
- At the end of Gemfile add:
ruby “2.3.1”
– or check version using ruby -v - Login to your heroku account
$ heroku login - 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. - deploy your code by running the command:
$ git push heroku master - The application is now deployed. Ensure that at least one instance of the app is running:
$ heroku ps:scale web=1 - Run the database migration:
$ heroku run rake db:migrate - 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 - Do mongodb installation, see instructions bellow:
Installing mongodb Add-on
- Run the command: heroku addons:create mongolab:sandbox
- 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 - Add production DB connection in your config/mongoid.yml:
1
2
3
4
5
6
7production:
clients:
default:
uri: <%= ENV['MONGODB_URI'] %>
options:
skip_version_check: true
safe: true - 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
- You can view information about your running app using one of the logging commands in real time using:
$ heroku logs –tail - 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