【问题标题】:Having a lot of trouble with rails3.1 heroku deployrails3.1 heroku deploy有很多麻烦
【发布时间】:2011-10-18 04:12:41
【问题描述】:

我在部署一个简单的 rails3.1 应用程序时遇到了很多麻烦。似乎有两个主要问题。

  1. 由于资产管道,资产未加载到生产环境中。
  2. 我使用默认的 db sqlite3 进行开发。 Heroku 使用 postgresql。

基本上,我希望我的从开发到部署的工作流程尽可能无缝。任何人都可以推荐设置我的开发环境的最佳方法,以便当我 $git push 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

【问题讨论】:

    标签: ruby-on-rails deployment heroku asset-pipeline


    【解决方案1】:

    在您提交之前运行以下命令来预编译您的资产:

    $> bundle exec rake assets:precompile
    

    除了放置

    之外,您不需要为heroku数据库设置任何东西
    gem 'pg' 
    

    在您的 gemfile 的生产部分。它自己解决了所有其他问题。

    我经常使用的一些不错的技巧是:

    $> heroku db:push
    $> heroku db:pull
    

    阅读推和拉here

    我在 mysql 上进行本地开发,因为它有最好的前端恕我直言,但你也可以使用 sqlite3 或 postgres,这取决于你想在原始表中工作多少。

    【讨论】:

    • 哈哈!,我认为它有效。刚刚用一个新的普通 Rails 应用程序试了一下,现在就显示了 rails 标志。现在我将使用我的实际应用程序进行尝试。谢谢
    • 不,但不能与我的实际应用程序一起使用。只是不断收到 500 错误页面
    • 如果您在使用开发机器上的 pg gem 时遇到问题,请阅读here
    • 您还需要使用“heroku log”命令获取 heroku 日志文件,这应该会告诉您为什么会收到 500 错误。
    【解决方案2】:

    我遇到了这个问题,但我改用了 cedar 堆栈,这似乎解决了资产问题。至于数据库,只需指定

    group :production do
        gem 'pg' 
    end
    

    在宝石文件中

    【讨论】:

    • 我是否还需要指定一个开发 gem 组,或者 bundler 是否假定 gem 'sqlite3' 仅用于开发?
    • 我使用 gem 'sqlite3', '1.3.4', :group => :development 指定它
    【解决方案3】:

    实际上,我使用了您两个答案中的信息来使其正常工作。我的资产问题通过bundle exec rake assets:precompile 解决,我的数据库问题通过

    解决
    group :production do
        gem 'pg' 
    end
    

    并添加以下内容:

    group :development do
        gem 'sqlite3' 
    end
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多