Skip to content

Instantly share code, notes, and snippets.

@rcoproc
Forked from chair28980/new_rails_app.md
Created February 10, 2020 04:24
Show Gist options
  • Save rcoproc/c82ec484646fd4d041ebfc7bf3ee5f44 to your computer and use it in GitHub Desktop.
Save rcoproc/c82ec484646fd4d041ebfc7bf3ee5f44 to your computer and use it in GitHub Desktop.
New rails 6 app with postgresql and heroku deployment

Create a new rails 6 app with postgresql and heroku deployment

Before we begin

This guide aims to quickly take you thru the requisite steps to spin up a new rails app and easily deploy it using heroku.

Check your local

Lets check our local environment to make sure we're ready to go.

Check your ruby version (should be 2.6 or higher):

ruby -v

Check your rails version (should be 6.0 or higher): rails -v

Check your heroku cli version (v 7.35 at time of writing): heroku -v

Lets begin

Make sure you are logged into heroku: heroku login

Create new app: rails new myapp --database=postgresql

Create a welcome page: rails generate controller welcome

Modify app/views/welcome/index.html.erb to say something nice.

Add a root route to config/routes.rb: root 'welcome#index'

Verify everything is running: rails server

Make sure you are running the same ruby version locally as what is specified in the Gemfile.

Make sure project is all setup with git.

Deploy the app to heroku: heroku create

You can verify that the remote was added to your project by running: git config --list | grep heroku

Deploy your code: git push heroku master

Migrate the database (heroku): heroku run rake db:migrate

Make sure you are using the free version: heroku ps:scale web=1

Check the state of your heroku dynos: heroku ps

Visit the app in your browser: heroku open

View the logs: heroku logs

Tail the logs: heroku logs --tail

Run the rails console (heroku): heroku run rails console

Run rake commands example: heroku run <some command>

Create a Procfile in the root of the app directory touch Procfile

Insert the following into the Procfile: web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}

Set your enviroment:

echo "RACK_ENV=development" >>.env
echo "PORT=3000" >> .env
echo ".env" >> .gitignore
git add .gitignore
git commit -m "add .env to .gitignore"

You will need to setup a tmp/pids directory to run things they way we are setting them up here: mkdir -p tmp/pids touch tmp/pids/.gitkeep

Start webserver: heroku local

If everything looks good commit and push to git.

Then push to heroku: git push heroku master

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