Skip to content

Instantly share code, notes, and snippets.

@vuongpd95
Last active September 28, 2020 01:22
Show Gist options
  • Save vuongpd95/70a58d3dbe511cb5fb29f4cf42fe82b7 to your computer and use it in GitHub Desktop.
Save vuongpd95/70a58d3dbe511cb5fb29f4cf42fe82b7 to your computer and use it in GitHub Desktop.
Useful terminal commands while working with rails & heroku
# n for line number, r for recursive, -i for case insensitive, -R for regular expression
grep -n -r -i -R --exclude-dir=node_modules '--include=*.'{slim,erb,js} "PATTERN" .
LOCAL:
# create a rake task
rails g task <task-name> # change lib/task/<task-name>.rake to desc the task
# to create database base on database.yml
rails db:create # OR rake db:create
# to run all migrates
rails db:migrate # OR rake db:migrate
# to seed fixtures
rails db:seed # OR rake db:seed
# to drop db
rails db:drop # OR rake db:drop
HEROKU:
# create a heroku app
heroku login # login to heroku from CLI
heroku create --remote <remote-name> <heroku-app-name> # setup the remote name for the dyno locally as well as creating a heroku app
# heroku doesn't allow customers to create and drop db
heroku run rails db:migrate # to create db
heroku restart && heroku pg:reset DATABASE --confirm APP-NAME && heroku run rake db:migrate # to drop db and recreate
# show information of remote
git remote show <remote-name>
# if you want to change the remote name of your heroku app locally from heroku to production
git remote get-url heroku # first, get the url of remote named heroku
git remote add production <url> # second, add remote name production with the url of the above step
git remote rm heroku # last, simply remote the old remote name
# push code to heroku
# heroku remote name: production, staging; your branches: master:production, master:staging
git push production master:production
git push staging master:staging
# set default heroku remote to staging remote
git config heroku.remote staging
# config rails master key for heroku production remote
heroku config:set RAILS_MASTER_KEY=<your-master.key content> -r production
# see dyno information of remote production
heroku -ps --remote production
# get information of an app database to use pgadminIII to connect
heroku pg:credentials:url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment