Full Stack Developer
Creating a new Rails app is super easy by itself. And, creating a Rails app set up as an API is not much different.
Because we are planning on deploying our app to Heroku we need to set it up with PostgreSQL as the database.
The default database in Rails is SQLite, but it is not supported by Heroku
Run the following line in your terminal to update Rails
gem update rails
and then this line to get the current version of Rails
rails new <<APP_NAME>> --api --database=postgresql
Replace thewith the actual name of your app
Keep track of the development of your API by storing your code on GitHub.
Check this link to see how to add an existing project to a Github repository.
Follow this link to the Heroku Sign up page.
Next, we will need to install the Heroku CLI to be able to deploy our little project.
Check this link to see how to install the Heroku CLI.
Once installed the
command is available from your terminal.
Run the following command in your terminal and enter your Heroku credentials when prompted
Press Enter at the prompt to upload your existing ssh key or create a new one, used for pushing code later on
Run the following command in your terminal to create a new app on Heroku
After that, we are all set up to deploy our app to Heroku!
We are finally here!
Run the following commands in your terminal to deploy your app to Heroku
git add . git commit -m "Deploy my super awesome Rails API" git push heroku master
Side note — if you are working on a different branch from the master branch. You can run the following command to deploy your code
For example, if you are working on the
git push heroku feature-branch:master
That’s it, our Rails API is now live!
It’s an API-only application, it’s using PostgreSQL as the database and it’s deployed to Heroku.
Congratulate yourself. And then, get back to work, you have only begun.
Thanks for reading. And hopefully, this article helps you out.
Create your free account to unlock your custom reading experience.