Deployed to Heroku : Rails Project


 Deployed to Heroku : Rails Project



If you haven’t deployed to Heroku before and this is your first time, feel free to just skim this section. It’s meant to be a handy reference for later.


We’ll do a quick overview of how it will work. It’s not meant to be a step-by-step guide… for that, please check out Heroku’s “Getting Started with Rails 5.x” guide. A typical convention with Heroku commands is that they’re prefixed with either $ heroku run or just $heroku, so running a database migration on Heroku is $ heroku run rails db:migrate and using the console is $ heroku run console

  • Download and install the Heroku CLI. You’ll likely need to set up the proper SSL configuration so your computer is able to securely move files to and from Heroku.
  • Install Heroku’s special gems – in Rails 4, there were some changes that broke Heroku so they made a really simple gem that you’ll need to add to your application
  • Install the correct database gem – if you’ve been using SQLite3 as your development database, you’ll need to set up PostgreSQL for production since it’s the only database Heroku uses. This will mean adding the pg gem to your gemfile and putting the correct fields into your database.yml file.
  • Create a new Heroku application from the command line using $ heroku create. This will also add a new remote to your Git setup so that Git knows where to push your app (so you don’t need to worry about that).
  • Ready? Push using the command $ git push heroku master.
  • But wait, there’s more! The last step you’ll need to do is manually set up your database. Any time you run migrations or otherwise alter your database, you will need to remember to also run them on Heroku. If it’s your first database, you’ll likely do something like $ Heroku run rails db:migrate. If you’ve set up seeds, you can also run them no


Essential Heroku Commands

A brief list of Heroku commands you should know:

  • $ heroku run rails db:migrate
  • $ heroku run console gives you a Rails console, though in Production (so don’t mess around with things, this is real data!)
  • $ heroku logs -t shows you your server logs (like you’re used to when running $ rails server) on a streaming basis (which is the result of the -t, or “tail” flag). See this Heroku post for more information on logging.
  • $ heroku restart – for if your application has failed and won’t start up. See this SO post for more.





Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5