【问题标题】:Macports installation of postgres is not working with ruby on railspostgres 的 Macports 安装不适用于 ruby​​ on rails
【发布时间】:2012-12-23 01:34:03
【问题描述】:

我正在尝试安装 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 和命令 sudo port install postgresql83 postgresql83-server 安装了 postgres,并且 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.

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

【问题讨论】:

    标签: ruby-on-rails postgresql macports localserver


    【解决方案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 只支持前者

    【讨论】:

    • 嘿乍得,非常感谢您的回复。我还没有尝试您的后一个建议,但我正在尝试使用自制软件而不是端口来干净地重新安装 Ruby 1.9。不过,这两者似乎是矛盾的。我可能会再发一篇文章,看看我是否可以彻底清除系统中的 ruby​​ 并重新开始;我不确定我是否可能不小心擦掉了我的系统红宝石。再次感谢!
    • 我会推荐 rvm - rvm.io 比自制软件麻烦得多,让您轻松切换版本、升级或恢复到系统版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2013-05-21
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多