Ruby on Rails
TutorialStepOnePostgresql

<— Tutorial | TutorialStepTwo —>

Create a database named rails_production

using linux console:

su
(Enter Password)
su postgres
createdb rails_production

Create a user for the database

Using linux console


createuser -P
(Give a name)
(Give a password)
(Set Permissions)

To create the table using migrations see instructions at TutorialStepOneMigrations. Note also the instructions at the bottom for connecting Ruby with Postgres.

To create the table by hand do the following:

Sql code to create the table

CREATE TABLE people (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL default ‘’,
street1 TEXT NOT NULL default ’’,
street2 TEXT NOT NULL default ‘’,
city TEXT NOT NULL default ’’,
state TEXT NOT NULL default ‘’,
zip TEXT NOT NULL default ’’
);

CREATE INDEX idx_people_name ON people(name);

INSERT INTO people
VALUES (1, ‘Superman’, ‘123 Somewhere’, ‘’, ’Smallville’, ‘KS’, ’123456’);

Make sure you have the “Ruby ”http://wiki.rubyonrails.com/rails/pages/PostgreSQL" class="existingWikiWord">PostgreSQL adapter":http://www.postgresql.jp/interfaces/ruby/ installed

Get the C bindings:
   gem install postgres
or use the pure-Ruby bindings on Windows:
   gem install postgres-pr
or grab the C bindings for Windows here

change the adapter lines in config/database.yml to:

adapter: postgresql

Make sure you have configured local access by md5 autentication method in pg_hba.conf (not recommended) from

# "local" is for Unix domain socket connections only
local   all         all                               ident sameuser

to

  1. “local” is for Unix domain socket connections only
    local all all md5

or (recomended) configure config/database.yml to

host: 127.0.0.1

and change the listen_address option in postgresl.conf to like


listen_address = ‘127.0.0.1’

or the ip range you want to allow for external access

<— Tutorial | TutorialStepTwo —>

category:Tutorial