1. Switch To PostGres From SQL
The first step is to switch the database from SQL to Postgres. Locate the Gemfile and replace the following…
with the following…
Then run bundle install! Next we need to update the database.yml file before moving onto step 2. Locate the database.yml file in the config folder. Your config/database.yml file should look like this…
but you will replace it with the following…
That is it for step 1!
2. Login In To Heroku From The Terminal
Open the terminal on your Rails API project. Type in the following command in the terminal to log in to your Herkou account.
You should be prompted with a message to press any key to proceed.
Press any key and a browser window should open with a button to log in.
Please ensure you have a Heroku account before continuing with this article!
After selecting log in, your terminal should now display a message stating who heroku is currently logged in as.
3. Create The Heroku App
Time to create the Heroku app from the terminal. Use the following command to create a Heroku app.
heroku create app-name
4. Add Everything!
Use the following command to add all of the project for an update push.
git add .
5. Add An Update Message
Use the following command to add a message associated with the push update. This allows yourself and other developers to know the reasoning for the last update or what it consisted of.
git commit -m'first deploy'
6. Push the Updates to Heroku
Time to push the project to Heroku. Use the following command to do so.
git push heroku master
7. Migrate The Database To Heroku
Use the following command to migrate the database on Heroku. This is very important! Please don’t forget this step! This is the last step if no seeding if necessary!
heroku run rake db:migrate
8. Seed The Database If Necessary
If you have a seeds.rb file with data in your Rails API, please use the following command to seed the database on Heroku. This is the last step!
heroku run rake db:seed
You should now be able to access your database in the browser by accessing the correct route end points associated with your new Heroku app web address! I forgot how easy it was to complete the process. If I ever forget how to do deploy a Rails API to Heroku again, I can now reference this article, and you can too!
I hope you found this article helpful, and please feel free to reach out to me. You can connect with me on LinkedIn or check out my portfolio site! Thanks for reading, and I hope you have a great day!