Heroku上的Rails - 站点无法加载 - ActionView :: Template :: Error(资产管道中不存在资产“image.jpg”。)

问题描述 投票:2回答:1

我使用Rails构建了一个简单的网站,因此我可以将其部署到Heroku。它在当地完美运行,一切正常。它部署到Heroku,但是当打开网页(http://a-clean.herokuapp.com/)时,我显示以下错误:

我们很抱歉,但有些不对劲。

如果您是应用程序所有者,请检查日志以获取更多信息。

当我检查日志(在终端中运行heroku日志)时,它显示错误:

ActionView::Template::Error (The asset "a_clean_sample_1.jpg" is not present in the asset pipeline.)

到目前为止,这只是一个单页的网站,有几个部分。这是github存储库:https://github.com/webbc99/a-clean

它失败的图像加载到app / views / welcome / home.html.erb第57行。

Rails版本5.1.6,Ruby版本2.5.0

我已经仔细检查过图像实际上是在app / assets / images文件夹中,而image_tags正在使用文件扩展名。

我试过运行heroku run rake assets:precompile,我尝试使用rails12factor宝石,也没有它。我已经尝试在config / environments / production.rb中将config.assets.compile = false更改为true,这确实让页面加载但是所有图像都忽略了样式并且非常大。

令我感到困惑的是,我已经部署了其他几个rails应用程序,相同的rails版本,相同的ruby版本,而且之前都没有遇到过这个问题。

这是一个有效的应用程序:https://github.com/webbc99/presumptuous https://presumptuous.herokuapp.com/

任何帮助将不胜感激,谷歌搜索这几个小时没有运气。

ruby-on-rails ruby heroku assets pipeline
1个回答
0
投票

解决这个问题的最简单方法是;你需要运行如下;

  1. rails assets:precompile RAILS_ENV=production
  2. git add .
  3. git commit -m {message}
  4. git push heroku master(再次将代码推送到heroku)

我尝试从你的代码中做到这一点并且工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.