0

Postgres を使用している既存の Ruby on Rails プロジェクトで作業するために、Postgresql をインストールしようとしています。$ 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ました。

自分のコンピューターの username/pwd、postgres/blank pwd、pg/blank pwd、postgres/system pwd など、database.yml ファイルで usernames/pwd のいくつかの組み合わせを試しましたが、どれも機能していないようです。

最後に考えられるのは、次を使用してデータベース インスタンスを作成しようとしたときです。

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のインストールが機能することを保証することはできませんが、ここでの実際の問題は、Ruby1.8でrails3.2.9を実行していることです。発生する特定のエラーはconfig/initializers / session_store.rbにあり、キー:'_Jellyfish_session'を:key =>'_Jellyfish_session'に変更することで修正できますが、その後も他のエラーが発生する可能性があります。理論的には、Rails3.2.9はruby1.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 に答える