What is Heroku in the context of Rails applications?
Heroku is a cloud platform that lets you deploy, run, and manage Rails apps easily without managing servers.
Click to reveal answer
beginner
Which command initializes a new Git repository if you don't have one before deploying to Heroku?
git init initializes a new Git repository in your project folder.
Click to reveal answer
intermediate
Why do you need a Procfile in a Rails app for Heroku deployment?
A Procfile tells Heroku how to start your app, usually by running the web server.
Click to reveal answer
intermediate
What is the purpose of running heroku run rails db:migrate after deployment?
It runs database migrations on the Heroku server to update the database schema to match your app.
Click to reveal answer
intermediate
How do you set environment variables like secret keys on Heroku?
Use heroku config:set KEY=VALUE to securely set environment variables for your app.
Click to reveal answer
What is the first step to deploy a Rails app to Heroku?
ACreate a Git repository
BRun <code>rails server</code>
CInstall Node.js
DWrite a Dockerfile
✗ Incorrect
Heroku uses Git to deploy apps, so you must have a Git repository first.
Which file tells Heroku how to start your Rails app?
AProcfile
Bdatabase.yml
CGemfile
Dconfig.ru
✗ Incorrect
The Procfile specifies the command Heroku runs to start your app.
How do you push your code to Heroku for deployment?
Arails deploy
Bgit push heroku main
Cheroku deploy
Dgit push origin main
✗ Incorrect
You push your code to the Heroku remote repository using git push heroku main.
What command runs database migrations on Heroku?
Aheroku migrate
Brails db:migrate
Cheroku run rails db:migrate
Dgit migrate
✗ Incorrect
You run migrations on Heroku with heroku run rails db:migrate.
How do you set a secret key environment variable on Heroku?
Agit config secret_key abc123
Bheroku set secret_key=abc123
Crails secret set abc123
Dheroku config:set SECRET_KEY=abc123
✗ Incorrect
Use heroku config:set to set environment variables securely.
Explain the steps to deploy a Rails app to Heroku from a local project.
Think about preparing your app, connecting to Heroku, and updating the database.
You got /6 concepts.
Describe how environment variables are managed in Heroku for a Rails app.
Consider how to keep secrets safe and accessible in production.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of deploying a Rails app to Heroku?
easy
A. To put the app online without managing servers
B. To write Ruby code faster
C. To create a local database
D. To debug Rails code automatically
Solution
Step 1: Understand Heroku's role
Heroku is a platform that hosts apps so they can be accessed online without you managing the servers.
Step 2: Compare options
Options B, C, and D describe development or debugging tasks, not deployment.
Final Answer:
To put the app online without managing servers -> Option A
Quick Check:
Heroku deployment = online app hosting [OK]
Hint: Heroku hosts apps online, no server setup needed [OK]
Common Mistakes:
Confusing deployment with coding or debugging
Thinking Heroku manages local databases
Assuming Heroku speeds up writing code
2. Which command is used to push your Rails app code to Heroku?
easy
A. heroku push
B. heroku deploy app
C. rails deploy
D. git push heroku main
Solution
Step 1: Identify the correct git command
Heroku uses git to receive code. The correct command is 'git push heroku main' to push the main branch.
Step 2: Check other options
Options A, C, and D are not valid commands for pushing code to Heroku.
Final Answer:
git push heroku main -> Option D
Quick Check:
Push code with git push heroku main [OK]
Hint: Use git push heroku main to deploy code [OK]
Common Mistakes:
Using 'heroku push' which is invalid
Trying 'rails deploy' which doesn't exist
Confusing Heroku CLI commands
3. After pushing your Rails app to Heroku, which command runs database migrations on Heroku?
medium
A. heroku run rails db:migrate
B. rails db:migrate
C. git migrate heroku
D. heroku migrate db
Solution
Step 1: Understand migration on Heroku
To run migrations on Heroku's remote server, you use 'heroku run rails db:migrate'.
Step 2: Check other commands
'rails db:migrate' runs locally, 'git migrate heroku' and 'heroku migrate db' are invalid commands.
Final Answer:
heroku run rails db:migrate -> Option A
Quick Check:
Run migrations remotely with heroku run rails db:migrate [OK]
Hint: Run migrations remotely with heroku run rails db:migrate [OK]
Common Mistakes:
Running migrations locally instead of on Heroku
Using invalid git commands for migration
Confusing command order
4. You pushed your Rails app to Heroku but see an error when opening the app URL. What is a common cause?
medium
A. You did not install Ruby locally
B. You used 'git push origin main' instead of 'git push heroku main'
C. You forgot to run database migrations on Heroku
D. You opened the wrong browser
Solution
Step 1: Identify common deployment errors
Forgetting to run migrations on Heroku often causes errors because the database schema is not updated.
Step 2: Evaluate other options
You used 'git push origin main' instead of 'git push heroku main' means code wasn't pushed to Heroku, but question says code was pushed. Options A and D are unrelated to deployment errors.
Final Answer:
You forgot to run database migrations on Heroku -> Option C
Quick Check:
Missing migrations cause app errors on Heroku [OK]
Hint: Run migrations after push to avoid errors [OK]
Common Mistakes:
Ignoring migrations after deployment
Confusing git push origin with heroku
Blaming local environment for Heroku errors
5. You want to deploy a Rails app with environment variables for API keys on Heroku. Which is the correct way to set them before deployment?
hard
A. Add keys to config/application.rb file
B. Use 'heroku config:set KEY=value' command
C. Store keys in a local .env file only
D. Push keys directly in your code files
Solution
Step 1: Understand environment variables on Heroku
Heroku uses 'heroku config:set' to securely store environment variables like API keys.
Step 2: Evaluate other options
Adding keys to config/application.rb or pushing keys in code risks exposure. Local .env files are not sent to Heroku.
Final Answer:
Use 'heroku config:set KEY=value' command -> Option B
Quick Check:
Set env vars securely with heroku config:set [OK]
Hint: Use heroku config:set to add env variables securely [OK]
Common Mistakes:
Hardcoding keys in code risking leaks
Relying on local .env files for Heroku
Editing config/application.rb for secrets
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.