0

我正在尝试升级已经部署到 Heroku 的应用程序以使用 Rails 3.1 中的资产管道。我按照RailsCasts #282中的所有必要步骤操作,我的应用程序在本地运行良好。但是,当我推送到 Heroku 并尝试访问根路径时,我遇到了 sort 的错误"foobarbaz.png" is not precompiled。如果我从页面中删除第一个图像,我会在下一个图像中得到相同的错误,依此类推。所有图像都已推送到 Heroku,因此无需尝试引用不存在的图像。

我注意到当我将应用程序推送到 Heroku 时,我看到/没有看到以下输出:

-----> Preparing Rails asset pipeline
       Running: rake assets:precompile

我尝试在rake assets:precompile本地运行并不断收到以下错误:

rake aborted!
production database is not configured

由于使用 Heroku,我的 database.yml 文件中没有生产配置。当我尝试运行时heroku run rake assets:precompile,我收到以下错误:

rake aborted!
Application has been already initialized.

我已经在 application.rb 和我的环境文件中添加了必要的行,但我似乎无法让它工作!

4

2 回答 2

2

这个问题也发生在我身上,就我而言,这是因为我的 config/application.rb 上有以下行

config.assets.initialize_on_precompile = false

根据 Heroku ( https://devcenter.heroku.com/articles/rails-asset-pipeline ),在某些版本的 Rails 中似乎需要它,

在预编译资产时,在 Rails 3.x 中,您可以通过确保以下行位于 config/application.rb 中来防止初始化应用程序并连接到数据库:

config.assets.initialize_on_precompile = false

但在我的情况下,它抛出了“应用程序已经初始化”异常,并且在我删除它之后就消失了

由于 Heroku 日志在部署时并没有真正的帮助,我测试它的方式是在我的 heroku 实例上运行 assets precompile rake 任务:

heroku 运行 rake 资产:预编译

于 2013-05-17T03:26:23.843 回答
1

Heroku assumes you are doing your own precompiling (which you are having a problem with) if the file manifest.yml is present.

REMOVE manifest.yml from your public or public/assets folder.

Push the changes to heroku. Example below.

$ git rm public/assets/manifest.yml
$ git commit -m "remove precompile manifest"
$ git push -f heroku master

Run assets:precompile on heroku server. Enter:

$ heroku run rake assets:precompile
于 2013-02-17T01:18:18.787 回答