Skip to content

Instantly share code, notes, and snippets.

@chand
Last active November 5, 2023 18:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chand/7afbbfdccd7f2bb56f8862de105f1b59 to your computer and use it in GitHub Desktop.
Save chand/7afbbfdccd7f2bb56f8862de105f1b59 to your computer and use it in GitHub Desktop.
Deploy to Heroku from Ruby on Rails

Deploy to Heroku from Ruby on Rails

Deploying a new Ruby on Rails App to Heroku

Note: Your Ruby on Rails app must be set up in PostgreSQL, if it isn't, you will have to create a new Rails app in postgreSQL

In Heroku

  1. Create a free heroku account if you don't have one already

  2. Create a new App in Heroku, or select existing app you want to deploy to

  3. Install toolbelt (only need this once, if it is a new computer install again, there is a link on heroku to download)

  4. In App Settings > Reveal Config Variables > Edit "Secret_Key_base"

  5. Get the secret key base from the rails app in config > secrets.yml > development: secret_key_base, and paste it in heroku

In Command Line

Make sure you are in the project directory on the master branch and the project is pushed up and merged to github type in console:

heroku login (enter heroku account email and pw)
heroku git:remote -a my_app_name_in_heroku <-- project name that you set up in heroku
git push heroku master
heroku run rake db:migrate

In Heroku:

Under settings > heroku domain (copy and paste that url in a browser window)

To update an existing heroku site

  1. From inside your project folder, on the master branch, in command line:
git push heroku master
  1. Sometimes after updating an existing site, if there are errors on the site, run:
heroku run rake db:reset
heroku run rake db:migrate

To check the status

In your heroku account, check the activity tab

If you get this error when trying to reset or drop or migrate:

FATAL:  permission denied for database "postgres" / DETAIL:  User does not have CONNECT privilege.

In the command line

heroku pg:reset DATABASE_URL
heroku run rake db:migrate
heroku run rake db:seed (IF there is a seed file)

If you are using a twitter API:

  1. Make sure gem 'twitter' is included in your gem file
  2. add in the command line (in master branch):
heroku config:add TWITTER_CONSUMER_KEY=Your twitter consumer key
heroku config:add TWITTER_CONSUMER_SECRET=Your twitter consumer secret
heroku config:add TWITTER_ACCESS_TOKEN_KEY=Your twitter access token key
heroku config:add TWITTER_ACCESS_TOKEN_SECRET=Your twitter access token secret

Good Resource

Create a new Heroku account. Install the Heroku Toolbelt on your computer. The Heroku Toolbelt is installed by default in new Codecademy workspaces. 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 sqlite to

gem 'sqlite3', group: :development gem 'pg', '0.18.1', group: :production In Gemfile, add the rails_12factor gem::

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:

production: <<: *default database: db/production.sqlite3 to

production: <<: *default adapter: postgresql database: db/production.sqlite3 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:

$ heroku apps:info In the output, copy the address in the Web URL field. Open a new tab in your browser, and visit your app.

Heroku Rails Docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment