【问题标题】:rake assets:precompile trying to connect to production database?rake assets:precompile 试图连接到生产数据库?
【发布时间】:2011-12-21 08:14:44
【问题描述】:
$ rake assets:precompile
rake aborted!
could not connect to server: Network is unreachable
    Is the server running on host "192.168.163.70" and accepting
    TCP/IP connections on port 5432?

(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p0/bin/ruby /...]

所以我正在尝试在我的开发箱上预编译资产。出于某种原因,它会尝试连接到生产数据库 (192.168.163.70),如果连接失败,则会中止。

为什么会这样?我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails-3.1 asset-pipeline precompile


    【解决方案1】:

    我的一个 Rake 任务文件中有以下行

    require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'config', 'environment'))
    

    删除它解决了问题。

    【讨论】:

    • 我有同样的问题,即使我的项目中没有 rake 任务。 rake 在预编译资产时坚持连接到生产数据库。我可以通过更改 database.yml 以将生产指向 dev 数据库来临时解决它,但这使得部署指向错误的数据库变得容易。有更好的解决方案吗?
    • 我会尝试调试并找出导致资产预编译加载生产配置的原因。很遗憾,我没有更好的建议。
    【解决方案2】:

    检查您的 RAILS_ENV,它现在必须设置为 production

    【讨论】:

    • 将 Rails.env 放在 Application.load_tasks 之前给出“开发”
    • echo $RAILS_ENV 呢?另外,检查你的database.yml,也许你那里有问题。
    猜你喜欢
    • 2012-02-18
    • 2012-02-02
    • 2014-11-06
    • 1970-01-01
    • 2021-10-29
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    相关资源
    最近更新 更多