This tutorial aims to guide you on how to deploy a Rails application to Heroku, a cloud platform that aids in app deployment. By the end of the tutorial, you will be able to:
- Understand what Heroku is and how it works
- Deploy a Rails application to Heroku
- Troubleshoot common issues
The prerequisites for this tutorial are:
- Basic knowledge of Ruby on Rails
- An existing Rails application
To deploy a Rails application to Heroku, follow these steps:
Go to the Heroku website and sign up for a new account.
Install the Heroku Command Line Interface (CLI). This can be done by using the following command in your terminal:
$ brew install heroku/brew/heroku
Login to the Heroku CLI using the following command:
$ heroku login
Navigate to your Rails application's directory and create a new Heroku app:
$ heroku create
Deploy your Rails application to Heroku:
$ git push heroku master
Here are some practical examples:
Navigate to your Rails application's directory:
$ cd my_rails_application
Create a new Heroku app:
$ heroku create
Deploy your Rails application to Heroku:
$ git push heroku master
Expected output:
Counting objects: 375, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (354/354), done.
Writing objects: 100% (375/375), 36.85 MiB | 1.20 MiB/s, done.
Total 375 (delta 86), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.5.1
remote: -----> Installing dependencies using bundler 1.15.2
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> console, rake, web
remote: -----> Compressing...
remote: Done: 46.6M
remote: -----> Launching...
remote: Released v7
remote: https://my-rails-application.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/my-rails-application.git
* [new branch] master -> master
In this tutorial, we learned how to deploy a Rails application to Heroku. The next steps would be to learn how to manage your Heroku app, including scaling, configuring add-ons, and viewing logs.
Deploy a simple "Hello, World!" Rails application to Heroku.
Try to deploy a Rails application with a PostgreSQL database.
Try to troubleshoot a common deployment error.
Remember, practice is key to mastering any concept.