0

我正在尝试安装 Postgresql,以便与使用 postgres 的现有 Ruby on Rails 项目一起工作。但是,每次我$ rails s在项目目录中运行以启动本地服务器时,都会收到此错误。

=> 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

我怀疑这个问题与我的 database.yml 文件中的登录信息或我的 postgres 安装有关。

我已经使用 macports 和 command 安装了 postgres sudo port install postgresql83 postgresql83-server,并且 gem 同时运行了sudo env ARCHFLAGS="-arch x86_64" gem install pggem install pg -- --with-pg-config=/opt/local/lib/postgresql83/bin/pg_config.

我在 database.yml 文件中尝试了几种用户名/密码组合,例如我自己的计算机用户名/密码、postgres/空白密码、pg/空白密码、postgres/系统密码,但它们似乎都没有工作。

我能想到的最后一件事是,当我尝试使用

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'

正如安装程序所建议的,它给了我这个错误:

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.

我希望这是足够的信息。我发现了几个人们遇到类似问题的问题,但似乎没有一个解决方案对我有用。非常感谢您阅读本文。

4

1 回答 1

1

我不能保证 Postgres 安装正常,但这里的实际问题是您在 Ruby 1.8 上运行 rails 3.2.9。您遇到的具体错误位于 config/initializers/session_store.rb 中,可以通过将 key: '_Jellyfish_session' 更改为 :key => '_Jellyfish_session' 来修复,但是之后您也可能会遇到其他错误。我认为理论上 Rails 3.2.9 应该与 ruby​​ 1.8 一起使用,但如果可能的话,我建议更新到 1.9。

再看一遍之后,您应该可以通过执行以下操作使用 1.8 设置 rails 应用程序:

rails new myappname --old-style-hash

这会将所有默认文件设置为使用 1.8 样式的哈希,如下所示:

{ :key => 'value' }

而不是像这样的新样式:

{ key: 'value' }

请注意,1.9 支持这两种样式,但 1.8 仅支持前者

于 2013-01-09T03:43:30.010 回答