Heroku上的Rails应用无法加载 - ActionView::Template::Error(asset "image.jpg"不存在于asset pipeline中)。

3
我建立了一个简单的网站,使用Rails框架,以便可以将其部署到Heroku上。在本地运行得非常完美,一切正常。部署到Heroku也很顺利,但打开网页(http://a-clean.herokuapp.com/)时,会显示以下错误信息:
抱歉,出了点问题。
如果您是应用程序所有者,请检查日志获取更多信息。
当我检查日志(在终端中运行heroku logs)时,显示以下错误:
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 gem以及不使用它。我尝试将config/environments/production.rb中的config.assets.compile = false更改为true,这确实使页面加载,但所有图像都忽略了样式并且巨大。
真正让我困惑的是,我已经部署了几个其他的rails应用程序,同样的rails版本,同样的ruby版本,但之前没有出现过这个问题。

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

非常感谢您的帮助,已经花费了数小时在Google上搜索,但没有找到答案。

1个回答

0

解决这个问题最简单的方法是:您需要按照以下步骤操作:

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

我尝试从您的代码中执行它,效果很好。


谢谢,这个方法可行!我想我遇到的问题是我在Heroku上使用了Heroku run运行rake assets:precompile。非常感谢您提供及时的解决方案 :) - Aerodyne

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接