After developing a Rails app 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.
Heroku is a popular hosting service that is free to start using. Here’s how to deploy your Rails app to Heroku.
- Create a new Heroku account.
- Install the Heroku Toolbelt on your computer.
In the terminal, log in using the email address and password you used when creating your Heroku account:
$ heroku login
In Gemfile, add the
pg gem to your Rails project. Change:
gem 'sqlite3', group: :development
gem 'pg', '0.18.1', group: :production
- In Gemfile, add the
gem 'rails_12factor', group: :production
- In the terminal, install the gems specified in the Gemfile:
$ bundle install
Ensure config/database.yml is using the
postgresql adapter. Change:
- Commit your changes to git:
$ git add .
$ git commit -m "Heroku config"
- In the terminal, create an app on Heroku:
$ heroku create
- Push your code to Heroku:
$ git push heroku master
- If you are using the database in your application, migrate the database by running:
$ heroku run rake db:migrate
- If you need to seed your database with data, run:
$ heroku run rake db:seed
- Get the URL of your app and visit it in the browser:
In the output, copy the address in the
$ heroku apps:info
Web URL field. Open a new tab in your browser, and visit your app.
Check out Heroku’s Rails docs for more information.