Skip to content
Menu
Railshero
  • Blog
  • About Me
  • Contact Me
  • Privacy Policy
Railshero
deploying fails on heroku ?

Deploying fails on heroku? here’s what you can do to fix

Posted on July 13, 2021July 15, 2021 by Rails Hero

Use heroku logs

Heroku logs often provide in-depth useful information for debugging your rails apps, it shows us the exact block of code where the bug exists, sometimes it can be because of a typo or a problem with gem versions or something else.

We can also use heroku logs with –tail to continuously get live logs. We can also check our logs from the heroku dashboard, but its better to just use heroku cli. Here’s the complete guide on logging https://devcenter.heroku.com/articles/logging

Use latest version of Ruby and Ruby On Rails

Heroku has suspended support for old versions of ruby/ruby on rails, if you are using an older version of rails, consider upgrading it to the latest version such as rails6, upgrading rails version can sometimes be complicated, because of different dependencies and also because the methods used in earlier versions of rails has changed a lot in never version of rails.

Before upgrading your rails apps consider checking out the complete documentation on upgrading your rails version and also you can also checkout info on heroku stacks here: https://devcenter.heroku.com/articles/stack

Problems with gems

Check your rubygems for problems, some of the gems just don’t seem to work on heroku, gems such as ‘sqlite3’. If you are developing on a windows platform remove the ‘tzinfo-data’ gem, before deploying, also check if the version of your gems works with no issues with your current version of rails.

#File: Gemfile
#Just comment out the gems that doesn't work with heroku then run bundler and push the changes.
#gem 'sqlite3', '~> 1.4'
#gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Problem with assets

Most of the time heroku will fail to deploy because of problems with your assets, make sure to precompile your assets locally before pushing to heroku, you can even host your assets completely on a separate server or CDN, to make your app load even faster, here’s a tutorial on how to do so

Don’t use sqlite3

Don’t use sqlite on production environment, heroku doesn’t support sqlite, you can replace sqlite with heroku postgres or mysql or you can even use external databases such as amazon RDS or Digitalocean databases, or something similar to that.

You can use DATABASE_URL env variable to do so, heroku adds it by default when you use heroku postgres, and don’t forget to make changes to your database.yml file

#File: Gemfile
#Don't use sqlite3
#gem 'sqlite3', '~> 1.4'

#use postgres
group :production do
   gem 'pg'
end
#File: config/database.yml
production:
   url: <%= ENV['DATABASE_URL'] %>

Pending Database Migrations

After deploying your rails apps, if it shows up ‘500’ error, it’s most probably because you forgot to run database migrations, so go ahead and run the migrations using the command below

heroku run rake db:migrate

Check your environment variables

Check whether if you have added all the required environment variables for your app, and also check if there’s any typos on the values. If you are using Amazon S3 or something similar to store objects make sure to add the correct Environment variables, such as ACCESS_KEY_ID, SECRET_KEY, etc.

These were the most common ways that i figured out to help you deploy your rails apps on heroku with zero fails. If there’s any other issues you have faced or if you know a better way to fix those issues, please let me know.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tags

active record active storage assets assign to many associations attachment attachments authentication authorization avatar bootstrap cdn config database deploy deployments devise DRY environment variables file uploads Gemfile gems has_many helpers heroku index indexing initializer javascript pagination parameters postgres production public routes.rb ruby gem ruby gems search sendgrid server smtp stylesheets variants views voting

Recent Posts

  • Understanding the DRY Principle in Rails
  • Building Multi-tenant Applications with Rails
  • Rails Basics: Templating Engines
  • Deploying With Capistrano
  • Automated Testing in Rails

Archives

  • July 2023
  • June 2023
  • October 2021
  • September 2021
  • August 2021
  • July 2021

Categories

  • Active Record
  • Activity Logging
  • Apps
  • Assets
  • Attachments
  • Audio
  • Authentication
  • Authorization
  • Deployments
  • Error Pages
  • File Uploads
  • General
  • Heroku
  • Heroku
  • Pagination
  • Rails Basics
  • RubyGems
  • Search Engine Optimization
  • Search/Indexing
  • Testing
  • User Interface
  • Video
  • Views & Templating
  • Voting
  • Web Security
©2025 Railshero | Theme: Wordly by SuperbThemes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT