0

I'm attempting to install Postgresql in order to work with an already existing Ruby on Rails project which is using postgres. However, every time I run $ rails s in the project directory to start a local server, I get this error.

=> Booting Thin
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load':
/Users/******/Documents/Jellyfish/config/initializers/session_store.rb:3: syntax
error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_Jellyfish_session'
                          ^
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/engine.rb:588
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/engine.rb:587:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/engine.rb:587
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `send'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/******/Documents/Jellyfish/config/environment.rb:5
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /Users/******/Documents/Jellyfish/config.ru:3
from /opt/local/lib/ruby/gems/1.8/gems/rack-1.4.2/lib/rack/builder.rb:51:in `instance_eval'
from /opt/local/lib/ruby/gems/1.8/gems/rack-1.4.2/lib/rack/builder.rb:51:in `initialize'
from /Users/******/Documents/Jellyfish/config.ru:0:in `new'
from /Users/******/Documents/Jellyfish/config.ru:0

I suspect that this problem has to do with either the login information in my database.yml file or my installation of postgres.

I had installed postgres using macports, and the command sudo port install postgresql83 postgresql83-server, and the gem having run both sudo env ARCHFLAGS="-arch x86_64" gem install pg and gem install pg -- --with-pg-config=/opt/local/lib/postgresql83/bin/pg_config.

I've tried several combinations of usernames/pwd in the database.yml file, such as my own computer username/pwd, postgres/blank pwd, pg/blank pwd, postgres/system pwd, but none of them appear to be working.

The last thing that I can think of is that when I try to create a database instance using

sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'

as suggested by the installer, it gives me this error:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by initdb but was not found in the
same directory as "initdb".
Check your installation.

I hope this is enough information to work with. I've found several questions where people have had similar problems, but none of the solutions seem to be working for me. Thanks so much for reading this.

1 Answers1

1

I can't guarantee the Postgres installation works, but the actual problem here is that you are running rails 3.2.9 on Ruby 1.8. The specific error you are getting is in config/initializers/session_store.rb and could be fixed by changing key: '_Jellyfish_session' to :key => '_Jellyfish_session', however you'll likely hit other errors after that as well. I think in theory Rails 3.2.9 should work with ruby 1.8 but I would recommend updating to 1.9 if possible.

After looking at this a bit more, you should be able to set up a rails app with 1.8 by doing:

rails new myappname --old-style-hash

This will set up all the default files to use 1.8 style hashes which look like this:

{ :key => 'value' }

rather than the new style which look like this:

{ key: 'value' }

Note that both styles are supported in 1.9 but only the former is supported in 1.8

Chad
  • 768
  • 1
  • 6
  • 20
  • Hey Chad, thanks so much for your response. I haven't gotten around to trying your latter suggestion, but I'm instead trying to do a clean reinstallation of Ruby 1.9 using homebrew instead of ports. The two seem to be conflicting though. I'll likely make another post to see if I can completely wipe ruby from my system and start over; I'm not sure if I may have accidentally wiped my system ruby. Thanks again! – user1959978 Jan 10 '13 at 03:01
  • I would recommend rvm - https://rvm.io/ much less hassle than homebrew and lets you easily switch versions, upgrade or revert to system version. – Chad Jan 15 '13 at 18:00