Heroku

Deploy your Rails API onto Heroku

Posted on Updated on

 

Go to your Heroku Dashboard. Click “new”-> “create new app”

Screen Shot 2018-06-13 at 11.09.15 AM

Give your app a name and click “Create app”

Screen Shot 2018-06-13 at 11.12.34 AM

There are several ways to deploy

  • Heroku CLI  – push your project up to Heroku from your command line
  • Github – Heroku is connected to github, so everytime github is updated your app is
  • Dropbox connected
  • Container Registry

We will be using Heroku CLI. If you need to install  use these instructions

By default Heroku ONLY supports the master branch. If you want to push up a branch other than master follow these instructions.

Add Heroku as a remote to your project

heroku git:remote -a name-of-your-heroku-app

Push your project to Heroku

git push heroku master

Did you just get an error? Did you use sqlite3 for your project?

remote: An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote: continue.
remote: Make sure that `gem install sqlite3 -v ‘1.3.13’` succeeds before bundling
remote:
remote: In Gemfile:
remote: sqlite3
remote: !
remote: ! Failed to install gems via Bundler.

Click here for the fix.

Migrate and seed your database

In your command line run the following commands.

  • heroku run rake db:migrate
  • heroku run rake db:seed

Test your API using Postman

To get the address, just go back to the Heroku dashboard and click on “Open app” to get the link to your online api

Screen Shot 2018-06-13 at 12.56.13 PM

If you made it this far, your API should be deployed and now test it as you did locally (you did test locally didn’t you???).

The reason you need postman is if you setup your Rails API correctly when you query your site via browser you should get an error

This appname-api.herokuapp.com page can’t be found

but if you connect to it via postman you should get back the appropriate response

 

 

Advertisements