How to Host Your Ruby on Rails Backend to Heroku
This weekend I was competing once again in an international coding competition. I was a full stack engineer… I designed the frontend with Figma and built it with React, Javascript, CSS, HTML, and hosted the frontend on Netlify.
For the backend, I created a Ruby on Rails backend and hosted it to Heroku.
I successfully deployed my ruby on rails backend, but I was getting a 404 server error when I loaded the heroku link.
When your backend is a Ruby on Rails API, make sure that your:
- Respective method(s) is set up
- Your routes are configured
- You’re rendering JSON as a result
These simple mistakes held me back from displaying the JSON result I was looking for. When the server has the request, it responds either with a 200 server error (the task was completed) or a 404 error (the server could not load the data).
Now that my routes, index method and render JSON with a 200 status error are written and pushed to Github, I was able to return the expected JSON result by typing: *insert heroku link*/users.
Okay anyways, here is how you host you backend:
- Connect to Github:
Sign into your Heroku dashboard and connect your current backend repository. Once it’s configured correctly, the green checkmark will appear.
Once you’ve connected your Github repository, it’s time to configure your build pack.
Go to your settings, and click “Add buildpack”. Add the ‘heroku/ruby’ buildpack.
- Next, deploy your branch of choice.
I usually click the main branch to to deploy.
Once you’ve deployed your branch, you should be able to click “Open app”.
Once you open the app, make sure to put your designated route!
Happy hacking.
-Crystal