【问题标题】:What is the proper way to avoid the rake assets:precompile error on Heroku避免 rake 资产的正确方法是什么:Heroku 上的预编译错误
【发布时间】:2012-05-04 10:27:55
【问题描述】:

我在 Rails 3.2.2 上运行并部署在 Cedar 堆栈上。我仍然收到以下错误:

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?

即使guide 建议将config.assets.initialize_on_precompile 设置为false,但提到:

确保在部署前测试 rake assets:precompile 在本地。它 可能会暴露您的资产引用应用程序对象或 方法,因为这些仍然在开发模式的范围内 这个标志的值。

one 这样的一些文章建议使用Heroku labs。但即便如此,它也有其自身的含义,因为它仍处于测试阶段。

我已经阅读了其他几个在线资源,包括:

Rails 3.1 assets:precompile Connecting to Database

rake assets:precompile not working on heroku

都有不同的解决方案。那么避免这个错误的正确方法是什么?有人在 Heroku 实验室遇到过什么大问题吗?有更好的方法吗?

附言。只是要清楚。在本地运行 rake assets:precompile RAILS_ENV=developmentrake assets:precompile RAILS_ENV=production 是否正确?

【问题讨论】:

  • 错误日志是否告诉您一些有用的信息?
  • 这表明正在查看devcenter.heroku.com/articles/… 我已经阅读了有关在链接上应用解决方案的混合结果

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


【解决方案1】:

问题源于您的应用程序在运行该 rake 任务时尝试连接到 postgres。摆脱错误的唯一方法是阻止这种情况发生,或者使用您提到的user_env_compile 插件。

【讨论】:

  • 谢谢,刚刚遇到这个问题。
【解决方案2】:

(1) 我总是按照你的建议添加这个

config.assets.initialize_on_precompile = false

(2) 而且,如果使用 ActiveAdmin 和/或 Devise,在预编译资产时通过如下编码 routes.rb 排除它们的路由

  unless ARGV.join.include?('assets:precompile')
    ActiveAdmin.routes(self)

    devise_for :admin_users, ...etc....
    devise_for :users, ...etc...

    devise_scope :user do
    get "/login", ..etc
  end

根据here 和其他地方

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 2023-04-09
    • 2016-11-04
    • 2012-05-06
    相关资源
    最近更新 更多