Deployment on Heroku
This document is a guide for deploying a rails 3.2.x application on heroku. It assumes that the application has already been developed with sqlite. This guide provides the steps for switching to a postgresql database (required for heroku) and then deploying to Heroku.
Install Postgresql
The Heroku version of Postgresql is recommended. Installations are available for Windows and Mac OS. This guide assumes that you are using on of these two installations.
Setting up Postgresql
Postgresql needs to be running as a separate process. You also need to set up a role (user account) for your database.
Start Postgreql and open psql (command-line interface)
Windows: Start --> Programs --> PostgreSQL 9.2 --> SQL Shell (psql). Click enter until '#' prompt appears.
MacOS: Double-click installed Postgresql app to start server. An Elephant menu appears on the bar at the top of the screen to the right. From the Elephant menu, select "Open psql".
A role (user account) is created with the following command at the psql prompt:
create role craig with createdb login password 'secret'
craig can be set to any user name, but it should match what is used in the rails yml file.
Setting up Rails app for Postgresql
Here we assume that you already have your application running with Sqlite.
In the Gemfile, delete (or comment out) the line gem 'sqlite3' and add the line gem 'pg'. Run bundle install at the command line to install the new gem.
Replace the contents of the config/database.yml file with this content. Modify username and password so that it matches what you used for creating your Postgresql role. You may also want to modify the database names so that they appropriately refer to the name of your application.
At the command line, run rake db:create and then rake db:migrate to create the new development database.
You should now be able to run your server (rails server) using the Postgresql database.
Heroku Deployment
Heroku deployment instructions are online. Here are some additional tips:
- If you get an authentication error when pushing your application, try this command: heroku keys:add
- Don't forget the command heroku db:migrate in order to create your tables on Heroku.