Rails 4 on Heroku Share
This article covers how to run a Ruby on Rails application on Heroku. It assumes a knowledge of both Heroku and with Rails. If you are new to either please see the Getting Started with Rails 4.x on Heroku instead. This article assumes that you have a copy of the Heroku Toolbelt installed locally.
Most of Rails works out of the box with Heroku, however there are a few things you can do to get the most out of the platform. To do this you will need to configure your Rails 4 app to connect to Postgres, your logs need to be configured to point to STDOUT, and your application needs to have serving assets enabled in production.
Logging and assets
Heroku treats logs as streams and requires your logs to be sent to STDOUT. To enable STDOUT logging in Rails 4 you can add the rails_12factor gem. This gem will also configure your app to serve assets in production. To add this gem add this to your Gemfile:
This gem allows you to bring your application closer to being a 12factor application. You can get more information about how the gem configures logging and assets read the rails_12factor README. If this gem is not present in your application, you will receive a warning while deploying, and your assets and logs will not be functional.
Your application needs to be configured to use the Postgres database. Newly generated Rails 4 applications are configured to use sqlite. To use Postgres instead add the pg gem to your Gemfile:
We recommend using the same database in development and production to maintain dev/prod parity. You will need to remove the sqlite gem from your gemfile or place it in a non production group. You can read more about why you should not run sqlite on Heroku, which also contains detailed instructions on setting up Postgres locally.