Deploy Rails to Heroku
Deploy Rails to Heroku
Background
After developing aRailsapp locally, the next step is to put it online. After developing a Rails app and previewing it locally on your computer, the next step is to put it online so others can see it. This is called deploying your app.
Herokuis a popular hosting service that is free to start using. Here’s how to deploy your Rails app to Heroku.
Instructions
- Create anew Heroku account.
- Install theHeroku Toolbelton your computer.
- In the terminal, log in using the email address and password you used when creating your Heroku account:$ heroku loginCopy to clipboard
- InGemfile, add thepggem to your Rails project. Change:gem sqliteCopy to clipboardtogem'sqlite3',group::developmentgem'pg','0.18.1',group::productionCopy to clipboard
- InGemfile, add therails_12factorgem::gem'rails_12factor',group::productionCopy to clipboard
- In the terminal, install the gems specified in theGemfile:$ bundle installCopy to clipboard
- Ensureconfig/database.ymlis using thepostgresqladapter. Change:production: <<: *default database: db/production.sqlite3toproduction: <<: *default adapter: postgresql database: db/production.sqlite3
- Commit your changes to git:$ git add .$ git commit -m "Heroku config"Copy to clipboard
- In the terminal, create an app on Heroku:$ heroku createCopy to clipboard
- Push your code to Heroku on themainbranch:$ git push heroku mainCopy to clipboard
$ heroku login
Copy to clipboard
$ heroku login
gem sqlite
Copy to clipboard
gem sqlite
gem 'sqlite3', group: :developmentgem 'pg', '0.18.1', group: :production
Copy to clipboard
gem 'sqlite3', group: :developmentgem 'pg', '0.18.1', group: :production
gem 'rails_12factor', group: :production
Copy to clipboard
gem 'rails_12factor', group: :production
$ bundle install
Copy to clipboard
$ bundle install
production:
<<: *default
database: db/production.sqlite3
production:
<<: *default
adapter: postgresql
database: db/production.sqlite3
$ git add .$ git commit -m "Heroku config"
Copy to clipboard
$ git add .$ git commit -m "Heroku config"
$ heroku create
Copy to clipboard
$ heroku create
$ git push heroku main
Copy to clipboard
$ git push heroku main
Note: If you’re unable to push your code, you may have skipped a step or have a differently named branch. 11. If you are using the database in your application, migrate the database by running:bash $ heroku run rake db:migrate12. If you need to seed your database with data, run:bash $ heroku run rake db:seed13. Get the URL of your app and visit it in the browser:bash $ heroku apps:infoIn the output, copy the address in theWeb URLfield. Open a new tab in your browser, and visit your app.
Check outHeroku’s Rails docsfor more information.
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Complete Payment to Unlock Full Guide & Source Code
You are viewing the 30% preview. Join TopCourseAI Pro to unlock the remaining 70% of this article, unblur all code snippets, and gain full access to all 412 technical projects and guides.
Ready to access the complete step-by-step tutorial?
Gain full unhindered access to all 412 technical projects and guides, unblur all source code snippets, and download runnable scripts.
Decision Trees for Classification and Regression
Next BlueprintDeploying a Back-End with Heroku
Related Blueprints & Guides
View all 166 →Accessibility on the Platform
Codecademy is committed to providing a high-quality learning experience for all learners. That includes accommodating different usage forms such as auditory, motor, or visual restrictions, limited hardware, or other acce...
Web developmentAffordances, Signifiers, and Clickability
For users on the web, the mouse click is perhaps the most fundamental human-computer interaction. The webbecamethe web partially through the power ofhypertext, or text in one document that links to other documents or res...
Web developmentAuthentication and OAuth
Authenticationis the process used by applications to determine and confirm identities of users. It ensures that the correct content is shown to users. More importantly, it ensures that incorrect content is secured and u...
Ready to build production-grade AI systems?
Enjoyed this guide? Continue exploring our library of 166+ production blueprints, multi-agent swarms, and autonomous agent systems with 100% unblurred, executable source code.