在Rails3.1 Heroku部署方面有很多麻烦
-
22-10-2019 - |
题
我在部署一个简单的Rails3.1应用程序时遇到了很多麻烦。似乎有两个主要问题。
- 由于资产管道,资产没有在生产环境中加载。
- 我使用默认DB SQLite3开发。 Heroku使用PostgreSQL。
基本上,我希望我的开发工作流程尽可能无缝。任何人都可以推荐设置我的开发环境的最佳方法,以便当我推动Heroku时,一切都可以正常工作。
我想最好在开发环境中使用PostgreSQL,任何人都知道如何进行设置?
我应该使用独角兽吗?薄的?
我应该使用其他可能没有听说过的宝石吗?
我感到沮丧,因为我已经到了可以在开发环境中构建非常酷的东西的地步,但是不知道如何在线上获得应用程序。也许我在看这一切。让我知道。
当我尝试这样做时,我会遇到此错误:
group :production do
gem 'pg'
end
Installing pg (0.11.0) with native extensions /home/work/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/home/work/.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
--without-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=/home/work/.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
解决方案
在您的提交运行以下以下以预编译您的资产之前:
$> bundle exec rake assets:precompile
除了放置外,您不需要为Heroku数据库设置任何内容
gem 'pg'
在您的Gemfile的生产部分。它独自一人将其全部弄清楚。
我使用的一些不错的技巧是:
$> heroku db:push
$> heroku db:pull
阅读有关推送的信息 这里
我在MySQL上本地开发,因为它具有最佳的前端恕我直言,但是使用SQLite3或Postgres,您会没事的,具体取决于您想在原始表中工作的数量。
其他提示
我遇到了这个问题,但是我更改为Cedar堆栈,这似乎解决了资产问题。至于DB,只需指定
group :production do
gem 'pg'
end
在Gemfile中
实际上,我使用了您两个答案中的信息来使其正常工作。我的资产问题解决了 bundle exec rake assets:precompile
我的数据库问题得到了解决
group :production do
gem 'pg'
end
还添加了这个:
group :development do
gem 'sqlite3'
end
不隶属于 StackOverflow