Rails and Postgres


#1

Hi, I’m new to Ruby on Rails and am having a little difficulty working
through the ‘Rolling with Ruby on Rails’ tutorial. Can anyone help?

I’m trying to get the cookbook application to work via a Postgresql db.
But get the following error when trying to access
http://127.0.0.1:3000/recipe/new

Errno::EINVAL in RecipeController#new
Invalid argument
RAILS_ROOT: ./script/…/config/…

I’m using Ruby version ruby182-15.exe (Windows XP Home) running
Postgresql version 8.1

Here’s the console output:

C:\InstantRails\rails_apps\cookbook>ruby script/server
=> Booting WEBrick…
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2006-05-22 00:32:20] INFO WEBrick 1.3.1
[2006-05-22 00:32:20] INFO ruby 1.8.2 (2004-12-25) [i386-mswin32]
[2006-05-22 00:32:20] INFO WEBrick::HTTPServer#start: pid=2684 port=3000
127.0.0.1 - - [22/May/2006:00:32:26 GMT Standard Time] "GET /recipe/new
HTTP/1.1
" 500 12418

  • -> /recipe/new

Any ideas as to what I’m doing wrong? Thanks for any help… Sorry if
this is a total newbie question!!


#2

Craig,

I worked through this tutorial with Postgres many months ago; I know
it works with Postgres, but the fine details of any tweaks I applied
aren’t exactly fresh in my mind.

That said, my guess is that you’ve got an error in your view or
controller, rather than some sort of Postgres issue. Check for any
typos; if you can’t find any, then post the full stack trace of your
error message which will probably give a better indication about where
things went off the rails .

Regards

Dave M.


#3

Wow! Thanks for the quick response David.

Here are the details.

recipe_controller.rb:

class RecipeController < ApplicationController
scaffold :recipe
end

Full trace is:
c:/ruby/lib/ruby/1.8/readbytes.rb:16:in read' c:/ruby/lib/ruby/1.8/readbytes.rb:16:inreadbytes’
c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/message.rb:32:in
read' c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb:30:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb:29:in
loop' c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/connection.rb:29:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/postgres-compat.rb:23:in
new' c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/postgres-compat.rb:23:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
connect' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/postgresql_adapter.rb:24:inpostgresql_connection’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in
send' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:inconnection_without_query_cache=’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/query_cache.rb:54:in
connection=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:inretrieve_connection’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in
connection' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:696:incolumns’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1969:in
attributes_from_column_definition' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1351:ininitialize_without_callbacks’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/callbacks.rb:236:in
initialize' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/scaffolding.rb:124:innew’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/scaffolding.rb:124:in
new' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:insend’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in
perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:inperform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:inperform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:inprocess_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in
process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:inhandle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:ineach’
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:indispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
require' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:inrequire__’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:inrequire’
script/server:3

And session dump is:

flash: !ruby/hash:ActionController::Flash::FlashHash {}


#4

I just did the tutorial with postgres (I like Postgres as it is a ACID
complaint DB), it worked find.

Can you post the code of your controller I may be able to do a quick
comparison check.

Some strange errors messages occur with rails.


#5

Also, does it matter which encoding is used for the postgresql db?


#6

Sure:

class RecipeController < ApplicationController
scaffold :recipe
end

Could you perhaps describe which versions of each file you were using?
And which/how you installed the postgres interpreter? Maybe I’m using
incompatible versions.

Thanks for your help.


#7

I doubt that matters. From your backtrace it is having trouble
connecting to the database at initialization time, do you have a
firewall or something like that …

Here’s a stanza from my database.yml …

development:
adapter: postgresql
database: rosebank_development
username: guido
password:
encoding: UTF8
host: localhost
port: 5444

What does your database.yml say?

If the problem persists, you may want to try using the Unix sockets
to connect instead …

– G.


#8

this is my first post


#9

On May 22, 2006, at 9:27 AM, Craig McDonnell wrote:

Also, does it matter which encoding is used for the postgresql db?

it depends on the encoding requirements of your application. :slight_smile:

…but for any generic Rails application… no…

You might try the postgres adapter not the postgres-pr one.

Robby


Robby R.
Founder & Executive Director

PLANET ARGON, LLC
Ruby on Rails Development, Consulting & Hosting


www.robbyonrails.com

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4968 [fax]