0
0
Ruby on Railsframework~30 mins

Heroku deployment in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Deploying a Ruby on Rails App to Heroku
📖 Scenario: You have built a simple Ruby on Rails web application on your computer. Now, you want to make it available on the internet so your friends can visit it anytime. Heroku is a platform that helps you put your app online easily.
🎯 Goal: Deploy a basic Ruby on Rails application to Heroku so it can be accessed via a web URL.
📋 What You'll Learn
Create a new Rails app with a homepage
Add a Procfile to tell Heroku how to run the app
Set the Ruby version in Gemfile
Initialize a Git repository and commit the code
Create a Heroku app using the Heroku CLI
Push the code to Heroku to deploy
Open the deployed app in a browser
💡 Why This Matters
🌍 Real World
Deploying web applications to Heroku is a common way to share your projects with others online quickly and easily.
💼 Career
Many companies use Heroku or similar platforms to host their web apps. Knowing how to deploy apps is a key skill for web developers.
Progress0 / 4 steps
1
Create a new Rails app with a homepage
Run rails new myapp to create a new Rails app folder called myapp. Then, inside myapp, create a controller named home with an index action by running rails generate controller home index. Finally, set the root route to home#index in config/routes.rb by adding root 'home#index'.
Ruby on Rails
Need a hint?

Use rails generate controller home index to create the controller and view. Then set the root route in config/routes.rb.

2
Add a Procfile and set Ruby version
Create a file named Procfile in the root of your app folder with the line web: bundle exec puma -C config/puma.rb. Then, open Gemfile and add the line ruby '3.2.2' at the top to specify the Ruby version.
Ruby on Rails
Need a hint?

The Procfile tells Heroku how to start your app. Setting Ruby version in Gemfile helps Heroku use the right Ruby.

3
Initialize Git and commit your code
Run git init in your app folder to start a Git repository. Then run git add . to stage all files. Finally, commit the files with git commit -m 'Initial commit'.
Ruby on Rails
Need a hint?

Git tracks your code changes. Heroku uses Git to get your app code.

4
Create Heroku app and deploy
Run heroku create myapp-demo to create a Heroku app named myapp-demo. Then push your code with git push heroku main. After deployment, open your app in the browser with heroku open.
Ruby on Rails
Need a hint?

Use the Heroku CLI commands to create the app, push code, and open the live site.