0

I created a simple rails application:

1

$ rails new myapp1 -d postrgresql

2. Removed /public/index.html

3. Created the Homecontroller and the actions

4. Wrote the routes

myapp1::Application.routes.draw do

  root :to => "home#index"
  match 'about' => 'home#about'
  match 'contacts' => 'home#contacts'
  match 'projects' => 'home#projects'
end

5. Created the views and the default layout

6. The bottom line. Here is the database.yml

development:

  adapter: postgresql
  encoding: unicode
  database: myapp1_db
  host: localhost
  pool: 5
  username: myapp1_user
  password: 1234
 
test:
  adapter: postgresql
    encoding: unicode
    database: myapp1_db
    host: localhost
    pool: 5
    username: myapp1_user
    password: 1234

production:
  adapter: postgresql
    encoding: unicode
    database: myapp1_db
    host: localhost
    pool: 5
    username: myapp1_user
    password: 1234

and of course I created user and database

sudo -u postgres psql
postgres=# \password
postgres=# create user myapp1_user with password '1234';
postgres=# create database myapp1_db owner myapp1_user; 

But there are some worries:

1. Now I don't use any database, but in spite of this the application gives an error

PG::Error FATAL: Peer authentication failed for user "myapp1"

2. It seems like rails turns a blind eye to database.yml. Why does it use the user myapp1 instead of myapp1_user?

1
  • Make sure you add port as well in the config it either 5432 or 5433 check using 'lsof' command to confirm Commented Jun 2, 2012 at 9:07

2 Answers 2

1

Whitespace is significant in YAML.

production:
  adapter: postgresql
    encoding: unicode
    ...
    password: 1234

Should be:

production:
  adapter: postgresql
  encoding: unicode
  ...
  password: 1234
Sign up to request clarification or add additional context in comments.

Comments

1

Provide host and port in the database.yml file, like this:

    development:
      adapter: postgresql
      encoding: unicode
      database: myapp1_db
      host: localhost
      pool: 5
      username: myapp1_user
      password: 1234
      host: localhost
      port: 5432

Works like a charm on Ubuntu 12.04 LTS with Rails 3.2.x and PostgreSQL 9.1.x

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.