初めて Rails アプリを Heroku にデプロイしようとしたとき、多くの問題に遭遇しました。アプリがクラッシュしました。画像でログを確認できます: http://i.stack.imgur.com/bsx1b.png
さらに悪いことに、アプリケーションをローカルで見ようとすると、postgreSQL 環境で動作しませんでした。 .database.yml で sqLite3 を使用するように戻したところ、問題なく動作しました。問題は、pg gem を追加して bundle install を実行することに加えて、postgreSQL を実際にインストールする必要があることだと思いました。
ワンクリック インストーラー (Windows 7 64bit) で PostgreSQL をインストールすることにしました。再起動後、単純な Rails サーバーまたはバンドルのインストール コマンドが失敗し始めたので、ruby と rails 全体を再インストールしました。
これで rails server コマンドは正常に動作し、ローカル環境でアプリを見ようとすると別のエラーが表示されます。だから今、私はpgAdmin IIIとRailsを持っています
PG::Error
fe_sendauth: no password supplied
これを追ってみたのですが、「pg_hba.conf」が見つかりませんでした。答えは別のOSに基づいていたと思います。
また、バンドラーが機能せず、エラーが発生します...
質問: 1) ワンクリック インストーラーで postgreSQL をインストールするのは正しかったですか? これにより、RORが何らかの形で「クラッシュ」し、レールを完全に再インストールする必要があったためです。2) postgreSQL に関連するものをすべて削除し、Rails を再インストールして、すべてを最初からやり直そうと思います。どのような手順を踏む必要がありますか? 私が調べたすべてのリファレンスは、Windows 環境に適合していないようです。
私のgemfileには、
gem 'pg'
gem 'thin'
私のデータベースには、
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: utf8
database: mangfeel_development
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: utf8
database: mangfeel_test
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: utf8
database: mangfeel_production
pool: 5
timeout: 5000
PostgreSQL をインストールした後、現時点で発生しているエラー:
c:\ruby\myapp>rails server
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate'
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem'
from C:/RailsInstaller/Ruby1.9.3/bin/rails:18:in `<main>'
bundle install を実行すると:
Gem::InstallError: The 'json' native gem requires installed build tools
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
ですから、pgAdminIII、PostgreSQL、Ruby on Rails を完全に削除して、最初からやり直します。
デプロイはそれほど難しくないと思っていましたが、SQLite3 から PostgreSQL への移行は思ったよりも手間と時間がかかりました。この問題について何か助けていただければ幸いです。
-------------------------------------------------- -------------------------------------------------- --------------------
更新: すべてを再インストールした後、セットアップを最初からやり直しています。
SQLite3 バージョンのアプリが正常に動作することを確認しました。そこで、postgreSQL のセットアップに移りました。postgreSQL を最初にセットアップしたときに、次のエラーが発生しました。セットアップとは、config/database.yml を編集して、gem 'pg' をインストールし、gem 'sqlite3' を削除することを意味します。localhost:3000 に接続しようとすると、次のエラーが発生しました。
ActiveRecord::ConnectionNotEstablished
いくつかの調査の結果、データベースを設定するにはさらに多くの手順がある可能性があることがわかりました。だから私はbundleコマンドを実行しました、
bundle exec rake db:setup
しかし、コンソールでbundle exec rake db:setupを実行すると、次のエラーが表示されました。
Couldn't create database for {"adapter"=>"postgresql", "host"=>"localhost", "encoding"=>"utf8", "database"=>"db/myapp_test", "pool"=>5, "timeout"=>5000}
rake aborted!
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
c:/ruby/myapp/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:load => environment
localhost:3000 に接続しようとすると、ActiveRecord::ConnectionNotEstablishedではなく、上記のエラーが再び発生しました。
質問: 何を間違えましたか? 問題を解決するにはどうすればよいですか?