0
0
Ruby on Railsframework~10 mins

Heroku deployment in Ruby on Rails - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Heroku deployment
Prepare Rails app
Create Git repo
Login to Heroku CLI
Create Heroku app
Add Heroku remote to Git
Push code to Heroku
Heroku builds and deploys
App runs on Heroku server
This flow shows the steps to deploy a Rails app to Heroku, from preparing code to running live.
Execution Sample
Ruby on Rails
git init
heroku login
heroku create myapp
git push heroku main
heroku run rails db:migrate
This code initializes git, logs into Heroku, creates an app, pushes code, and runs database migrations.
Execution Table
StepActionCommand/ProcessResult/Output
1Initialize Git repositorygit initGit repo created locally
2Login to Herokuheroku loginUser authenticated with Heroku
3Create Heroku appheroku create myappHeroku app 'myapp' created with URL
4Add Heroku remotegit remote add heroku https://git.heroku.com/myapp.gitHeroku remote linked to Git
5Push code to Herokugit push heroku mainCode pushed; Heroku builds and deploys app
6Run database migrationsheroku run rails db:migrateDatabase schema updated on Heroku
7Open app in browserheroku openApp runs live on Heroku server
ExitDeployment complete-App is live and ready to use
💡 All steps completed successfully; app deployed and running on Heroku
Variable Tracker
VariableStartAfter Step 3After Step 5Final
Git repoNot initializedInitializedCode pushed to HerokuCode on Heroku remote
Heroku appNoneCreated 'myapp'App built and deployedApp running live
Database schemaLocal onlyLocal onlyMigrated on HerokuUp to date on Heroku
Key Moments - 3 Insights
Why do we need to run 'heroku run rails db:migrate' after pushing code?
Because the database on Heroku is separate and needs schema updates; see execution_table step 6.
What happens if you forget to add the Heroku remote before pushing?
Git won't know where to push the code; step 4 shows linking remote is required before step 5.
Why do we use 'git push heroku main' instead of just 'git push'?
Because 'heroku' is a special remote for deployment; pushing to it triggers Heroku build and deploy (step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what command creates the Heroku app?
Agit init
Bgit push heroku main
Cheroku create myapp
Dheroku run rails db:migrate
💡 Hint
Check step 3 in the execution_table where the app is created.
At which step is the code actually sent to Heroku servers?
AStep 4
BStep 5
CStep 2
DStep 6
💡 Hint
Look for 'git push heroku main' in the execution_table.
If you skip running 'heroku run rails db:migrate', what happens?
ADatabase schema on Heroku will be outdated
BGit remote will be missing
CApp will not build
DHeroku app won't be created
💡 Hint
See step 6 in execution_table about database migrations.
Concept Snapshot
Heroku Deployment for Rails:
1. Initialize Git repo with 'git init'.
2. Login to Heroku CLI using 'heroku login'.
3. Create app with 'heroku create appname'.
4. Add Heroku remote to Git.
5. Push code using 'git push heroku main'.
6. Run 'heroku run rails db:migrate' to update database.
7. App runs live on Heroku URL.
Full Transcript
Deploying a Rails app to Heroku involves several clear steps. First, you prepare your Rails app and initialize a Git repository locally. Then, you log in to Heroku using the Heroku CLI. Next, you create a new Heroku app which gives you a unique URL and Git remote. You add this remote to your local Git configuration. After that, you push your code to Heroku using 'git push heroku main', which triggers Heroku to build and deploy your app. Since the database on Heroku is separate, you run migrations there with 'heroku run rails db:migrate'. Finally, your app is live and accessible on the web. Each step builds on the previous, ensuring your app is properly deployed and ready for users.