【问题标题】:Rails on Heroku - Site does not load - ActionView::Template::Error (The asset "image.jpg" is not present in the asset pipeline.)Heroku 上的 Rails - 站点未加载 - ActionView::Template::Error(资产“image.jpg”不存在于资产管道中。)
【发布时间】:2019-02-15 06:27:12
【问题描述】:

我使用 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​​ 版本,而这些应用程序之前都没有遇到过这个问题。

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

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

【问题讨论】:

    标签: ruby-on-rails ruby heroku assets pipeline


    【解决方案1】:

    解决此问题的最简单方法是;你需要按如下方式运行;

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

    我尝试从您的代码中执行此操作并且工作正常。

    【讨论】:

    • 谢谢,这成功了!我认为我遇到的问题是我正在运行 rake assets:precompile on heroku with heroku run。非常感谢您的及时解决:)
    猜你喜欢
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    相关资源
    最近更新 更多