Create a Rails project with a postgresql database

If you already have Rails setup the defaults are to create a connection for a  SQLite database.

To switch this to a PostgeSQL database.

First install a PostgreSQL database on your machine for dev and test.

For apple computers, I suggest the Postgres.app.

You also need the PG gem which connects PostgeSQL to Rails. To verify everything is ready to go, run

To create a new project with a PostgreSQL database run

This creates a new project connected postgresql

The connection settings for you new project are in the database.yml under config. Here are the default settings as of rails 4.2.4.

 

Common Rake Commands

create databases

run a Migration

rollback a migration

seed the database

drop the databases

 

Create a new Rails project with a specific version

To create a new project in rails with a specific version.

First make sure you have the rails version gem installed, then create your project.

example: