Help to connect Postgres and Ruby on Rails

Hello to everyone, I have a problem that is giving me a headache, and
trying to do a project in Ruby on Rails and I need to connect with a
Data Base that is en Postgres, the truth is that I didn't think that
it was so hard to connect a DB with postgres because I was working with
Msyql and everything was easy. This are the thinks that I have install
in my computer.

1. Debian GNU/Linux, kernel 2.4.27-2-686.
2. Ruby 1.8.2
3. Postgresql 7.4.7-6 sarge1
4. Gems: actionmailer-1.2.5, actionpack-1.12.5, actionwebservice-1.1.6,
activerecord-1.14.4, activesupport-1.3.1, postgres-pr-0.2.1,
rails-1.1.6, rake-0.7.1
5. ruby-postgres-0.7.1.tar.tar

The error is that after I install everything that I need, I can't
connect with my DB, in my project in the folder /app/models I made a
archive with the same name off my table, remembering that my real table
the name is in plural bout in my project in singular, the thinks that I
wrote look something like this

ActiveRecord::Base.establish_connection(
    :adapter => "postgresql",
    :host => "localhost",
    :port => "5432",
    :database => "mundo",
    :username => "usuario",
    :password => "123456"

   )

class Usuario < ActiveRecord::Base

end

When I try to save something in my DB the error that appears is like
this

TypeError in PruebaController#guardar
can't convert String into Integer

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
`connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
`postgresql_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in
`send'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in
`connection_without_query_cache='
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/query_cache.rb:54:in
`connection='
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in
`retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in
`connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:696:in
`columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1969:in
`attributes_from_column_definition'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1351:in
`initialize_without_callbacks'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:236:in
`initialize'
app/controllers/prueba_controller.rb:9:in `new'
app/controllers/prueba_controller.rb:9:in `guardar'
-e:4:in `load'
-e:4
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'

Request
Parameters: {"commit"=>"Guardar", "usuario"=>{"apellido"=>"GGGGGG",
"cedula"=>"888888", "nombre"=>"MMMMM", "telefono"=>"5555555"}}
Show session dump
flash: !ruby/hash:ActionController::Flash::FlashHash {}

Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Pleas if someone know how to help me I'll be grateful.

From Venezuela. El_gocho says thank you.

P.S: sorry if I wrote something wrong, my English writhing is not so
good.

El_gocho wrote:

> ActiveRecord::Base.establish_connection(
> :adapter => "postgresql",
> :host => "localhost",
> :port => "5432",
> :database => "mundo",
> :username => "usuario",
> :password => "123456"

> )

> TypeError in PruebaController#guardar
> can't convert String into IntegerThe problem is the line specifiying your port. it should be

    :port => 5432

That's most likely a web server error, not a database error. Do you have your web server running on port 3000? It looks like it's not. Make sure your web server is running (e.g., script/server )

Michael Glaesemann
grzm seespotcode net

> and now I have this problem, when I try to save some data I received a
> javascript error that says "The connection was refused when
> attempting to contact localhost:3000 ", there where a friend that
> wrote me that the :host and :por are no necessary, I try the too
> bout I
> gat the same javascript error.That's most likely a web server error, not a database error. Do you
have your web server running on port 3000? It looks like it's not.
Make sure your web server is running (e.g., script/server )

Michael Glaesemann
grzm seespotcode net

Hello my friends, well I try all the you gays wrote me bout I don't
know
why I still have the problem, I just want to connect a DB that is in
Postgres with my project Ruby on Rails, bout nothing seems to work,
well
all that thinks that I had made are:
1. install all these:
o Debian GNU/Linux, kernel 2.4.27-2-686.
o Ruby 1.8.2
o Postgresql 7.4.7-6 sarge1
o Gems: actionmailer-1.2.5, actionpack-1.12.5, actionwebservice-1.1.6,

activerecord-1.14.4, activesupport-1.3.1, postgres-pr-0.2.1,
rails-1.1.6, rake-0.7.1
o ruby-postgres-0.7.1.tar.tar

2. in my project in the folder /app/models I made a archive with the
same name off my table, remembering that my real table the name is in
plural bout in my project in singular, the thinks that I wrote look
something like this

               ActiveRecord::Base.establish_connection(
               :adapter => "postgresql",
               :host => "localhost",
               :port => "5432",
               :database => "mundo",
                :username => "usuario",
                :password => "123456"
         )

class Usuario < ActiveRecord::Base

end

Ok, the first error that I had was these:

TypeError in PruebaController#guardar
can't convert String into Integer

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in

`retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in

`connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:696:in

`columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1969:in

`attributes_from_column_definition'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1351:in

`initialize_without_callbacks'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks.rb:236:in

`initialize'
app/controllers/prueba_controller.rb:9:in `new'
app/controllers/prueba_controller.rb:9:in `guardar'
-e:4:in `load'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'

Request
Parameters: {"commit"=>"Guardar", "usuario"=>{"apellido"=>"GGGGGG",
"cedula"=>"888888", "nombre"=>"MMMMM", "telefono"=>"5555555"}}
Show session dump
flash: !ruby/hash:ActionController::Flash::FlashHash {}

Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Well a friend wrote me that the host and port aren't necessary if my
data was local and it is, so I changed my connection for something
like
these

ActiveRecord::Base.establish_connection(
               :adapter => "postgresql",
               :database => "mundo",
                :username => "usuario",
                :password => "123456"
         )

class Usuario < ActiveRecord::Base

end

So after that, I have a different error is a javascript error that says

"The connection was refused when attempting to contact localhost:3000
",
and the error happens when a try to save something in my DB, my host is

running because I can see all my web pages bout if I what to save
something and I click the save button the javascript error appear.

I don't know if someone in this community can help me, with a
tutorial
or a example the connect Postgres and Ruby on Rails, or maybe tell me
what thinks do I have to install in what order. Please someone help me
I
don't want to give-up with these error.

From Venezuela. El_gocho says thank you.

P.S: sorry if I wrote something wrong, my English writhing is not so
good

El_gocho wrote:
> Hello to everyone, I have a problem that is giving me a headache, and
> trying to do a project in Ruby on Rails and I need to connect with a
> Data Base that is en Postgres, the truth is that I didn't think that
> it was so hard to connect a DB with postgres because I was working with
> Msyql and everything was easy. This are the thinks that I have install
> in my computer.This was answered in your previous post.

ilan

--
Posted viahttp://www.ruby-forum.com/.

Hello my friends, well I try all the you gays wrote me bout I don't
know
why I still have the problem, I just want to connect a DB that is in
Postgres with my project Ruby on Rails, bout nothing seems to work,
well
all that thinks that I had made are:
1. install all these:
o Debian GNU/Linux, kernel 2.4.27-2-686.
o Ruby 1.8.2
o Postgresql 7.4.7-6 sarge1
o Gems: actionmailer-1.2.5, actionpack-1.12.5, actionwebservice-1.1.6,

activerecord-1.14.4, activesupport-1.3.1, postgres-pr-0.2.1,
rails-1.1.6, rake-0.7.1
o ruby-postgres-0.7.1.tar.tar

2. in my project in the folder /app/models I made a archive with the
same name off my table, remembering that my real table the name is in
plural bout in my project in singular, the thinks that I wrote look
something like this

               ActiveRecord::Base.establish_connection(
               :adapter => "postgresql",
               :host => "localhost",
               :port => "5432",
               :database => "mundo",
                :username => "usuario",
                :password => "123456"
         )

class Usuario < ActiveRecord::Base

end

Ok, the first error that I had was these:

TypeError in PruebaController#guardar
can't convert String into Integer

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connectio­n_adapters/abstract/connection_specification.rb:220:in

`retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connectio­n_adapters/abstract/connection_specification.rb:78:in

`connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:6­96:in

`columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1­969:in

`attributes_from_column_definition'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1­351:in

`initialize_without_callbacks'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/callbacks­.rb:236:in

`initialize'
app/controllers/prueba_controller.rb:9:in `new'
app/controllers/prueba_controller.rb:9:in `guardar'
-e:4:in `load'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:172:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:161:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'

Request
Parameters: {"commit"=>"Guardar", "usuario"=>{"apellido"=>"GGGGGG",
"cedula"=>"888888", "nombre"=>"MMMMM", "telefono"=>"5555555"}}
Show session dump
flash: !ruby/hash:ActionController::Flash::FlashHash {}

Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Well a friend wrote me that the host and port aren't necessary if my
data was local and it is, so I changed my connection for something
like
these

ActiveRecord::Base.establish_connection(
               :adapter => "postgresql",
               :database => "mundo",
                :username => "usuario",
                :password => "123456"
         )

class Usuario < ActiveRecord::Base

end

So after that, I have a different error is a javascript error that says

"The connection was refused when attempting to contact localhost:3000
",
and the error happens when a try to save something in my DB, my host is

running because I can see all my web pages bout if I what to save
something and I click the save button the javascript error appear.

I don't know if someone in this community can help me, with a
tutorial
or a example the connect Postgres and Ruby on Rails, or maybe tell me
what thinks do I have to install in what order. Please someone help me
I
don't want to give-up with these error.

From Venezuela. El_gocho says thank you.

P.S: sorry if I wrote something wrong, my English writhing is not so
good

Is your database server running? Are you able to go the sql prompt?
Can you run queries from your sql prompt?
If you are using a GUI client for connecting to the database, use the
same parameters in your code to make database connection.

try using

host: 127.0.0.1 , instead of localhost

you don’t need to set the port if its 5432… plus that is an integer, not the string “5432” and I don’t know that the database driver can tell the difference.