Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## DEPLOY RAILS APP TO HEROKU ##
IN HEROKU =>
# Create a free heroku account if you don't have one already
# pick app you want to deploy (it can't be that is on sql, has to be postgresql) OR create a new app
** if your app was created in sql, to change to postgres is a bit involved, get help **
# create new app
# choose name for app
# install toolbelt (only need this once, if it is a new computer install again, there is a link on heroku to download)
# App Settings > Reveal Config Variables > Edit "Secret_Key_base"
# Get the secret key base from the rails app in config > secrets.yml > development: secret_key_base, and paste it in heroku
IN CONSOLE =>
# 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 site:
# from inside your project folder, on the master branch, in console =>
git push heroku master
* sometimes after updating an existing site, if there are errors on the site, run:
heroku run rake db:reset
* you might have to heroku run rake db:migrate after this *
# to check status
# heroku website > 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 Console =>
# 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:
# make sure gem 'twitter' is in your gem file
# add in console =>
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: https://www.codecademy.com/articles/deploy-rails-to-heroku
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: https://devcenter.heroku.com/articles/getting-started-with-rails4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.