2

私は自分自身にレールを教えています。私はプログラマーですが、Webプログラマーではありません。ここでマイケル・ハートルの本を読んでいます

アプリのデプロイを最初から開始することをお勧めします。同意します。そこで、Herokuのアカウントを取得し、セットアップなどを行いました。次に、最初のアプリであるgitと作品を作成しました。次に、Herokuのサイトのすべての指示に従いました。最後に、次のコマンドを使用してアプリをHerokuにプッシュするようになりました。

git push heroku master

この本は、Herokuがpostgresqlを望んでいるのに、私のマシンのアプリがsqlite3を使用しているため、この段階で問題が発生する可能性があると述べています。この本は、私のアプリのgemファイルの行をから変更することを提案しています

gem 'sqlite3'

gem 'sqlite3-ruby', :group => :development

それを試し、バンドルインストールを実行してから、アプリをプッシュしようとしました。運が悪いので、コンソールに次のメッセージが表示されます。

An error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
   Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.

!!Bundler経由でgemをインストールできませんでした。!!Herokuプッシュが拒否され、Ruby/railsアプリのコンパイルに失敗しました

そこで、HerokuのWebサイトが提案していることをここで試しました

gemfileを変更するには

これから:

gem 'sqlite3'

これに:

gem 'pg'

そこで、このアプローチを試し、「バンドルインストール」を実行しました。しかし、それもうまくいきませんでした。コンソールに次のメッセージが表示されます。

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2     for inspection.
Results logged to /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

このコマンドを実行しようとしました:

gem install pg

次のエラーメッセージで失敗しました:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config


Gem files will remain installed in /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2     for inspection.
Results logged to /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2/ext/gem_make.out

誰かがこれを手伝ってくれませんか。iveは障害にぶつかった。次に何をすべきかわからない。ありがとう

4

5 に答える 5

5

あなたの場合の適切な構成は、他の回答に既に投稿されています。便宜上、ここに添付します。

group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end

ただし、 を実行するbundle installと、バンドラーはすべての環境のすべての gem をインストールしようとすることに注意してください。後で、実行時に指定された環境の gem のみをロードします。

これが、ローカル マシンにもインストールしようとする理由pgです。

コンパイル エラーを解決するには、次の 2 つの方法があります。

  1. gemlibpqのコンパイルに必要なライブラリであるをインストールします。pg完全な PostgreSQL クライアントまたはスタックをインストールする必要はありませんlibpq。コンパイルに合格するには十分です。MacOSX では、homebrewを使用してインストールすることをお勧めします。

  2. インストールの実行時に不要なグループをスキップするようバンドラーに指示します。

     bundle install --without production
    

補足として、SQLite と PostgreSQL は 2 つの異なるデータベースであることに注意してください。本番環境とできるだけ似た開発環境を使用することは、常に良い考えです。私の個人的な提案は、PostgreSQL をローカル マシンにインストールし、開発と運用の両方で使用することです。

繰り返しますが、自作はあなたの友達です。

$ brew install postgresql
于 2012-04-26T09:47:04.540 に答える
2

Postgres をローカルにインストールする必要があります。Mac を使用しているようです。最も簡単な方法は、次のインストーラーを使用することです。

http://www.postgresql.org/download/macosx/

次に、Gemfile でこれに固執します。

gem 'pg'
于 2012-04-25T18:10:23.650 に答える
2

1) マシンに postgresql をインストールします。

2) 恒久的な修正 - .bash_rc ファイルに移動し、次を追加します。アプリのルート: PATH=$PATH:/Library/PostgreSQL/9.1/bin/ bundle install または PATH=$PATH:/Library/PostgreSQL/9.1/bin/ gem install pg

3) これで pg gem がインストールされました

この投稿は役に立ちました: http://excid3.com/blog/installing-postgresql-and-pg-gem-on-mac-osx/

于 2012-04-25T19:50:27.067 に答える
0

試す

group :production do
  gem 'pg'
end

group :development do
  gem 'sqlite3'
end
于 2012-04-25T18:07:53.647 に答える
0

pg がシステムにインストールされていないため、gem をインストールできないことがエラーの原因だと思います。

heroku は別のデータベースを使用することを勧めていませんが、私は次のように作業しました。

group :test, :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end
于 2012-04-25T18:12:53.667 に答える