Rails 在 Heroku 上 - 站点未加载 - ActionView::Template::Error(资产 "image.jpg" 不存在于资产管道中。)

Rails on Heroku - Site does not load - ActionView::Template::Error (The asset "image.jpg" is not present in the asset pipeline.)

我使用 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 gem 和不使用它。我尝试在 config/environments/production.rb 中将 config.assets.compile = false 更改为 true,这确实让页面加载但所有图像都忽略了样式并且很大。

真正让我困惑的是,我已经部署了其他几个 rails 应用程序,相同的 rails 版本,相同的 ruby 版本,其中 none这个问题之前。

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

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

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

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

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