-
You will need rails 6 installed. (GoRails)[https://gorails.com/setup/] is the best resource I have found to date.
-
You will need the (heroku cli)[https://devcenter.heroku.com/articles/heroku-cli#download-and-install] tool installed.
-
You will need NodeJS installed: https://nodejs.org/en/download/
-
You will need yarn installed: https://yarnpkg.com/lang/en/docs/install/
This guide aims to quickly take you thru the requisite steps to spin up a new rails app and easily deploy it using heroku.
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
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