【问题标题】:Image asset not present in the asset pipeline资产管道中不存在图像资产
【发布时间】:2020-03-16 05:25:26
【问题描述】:

这种情况是在开发中没有问题,但在生产中(预编译资产),在资产管道中找不到图像。

我觉得我遗漏了一些微妙的东西,但是在阅读了文档并在此站点上进行搜索后,我无法确定问题的原因。

来自 .html.erb 视图文件的 sn-p:

<div class="media-left">
   <figure class="image is-256x256">
      <%= image_tag('95090365.jpeg') %>
   </figure>
 </div>

预编译的镜像在 /public/assets :-

95090365-8976ee2cb59e500cd649fb288749282959ada00f93955c319300e4d85779d687.jpg

当我尝试加载相关视图时,页面上出现 500 错误,并在 log/production.log 中看到:

I, [2020-03-16T05:11:48.841878 #1]  INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e]   Rendering users/show.html.erb within layouts/application
I, [2020-03-16T05:11:48.842593 #1]  INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e]   Rendered users/show.html.erb within layouts/application (Duration: 0.6ms | Allocations: 406)
I, [2020-03-16T05:11:48.842735 #1]  INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e] Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.4ms | Allocations: 1785)
F, [2020-03-16T05:11:48.843367 #1] FATAL -- : [d802e301-bbe2-4881-83ba-8e107adaa04e]   
[d802e301-bbe2-4881-83ba-8e107adaa04e] ActionView::Template::Error (The asset "95090365.jpeg" is not present in the asset pipeline.):
[d802e301-bbe2-4881-83ba-8e107adaa04e]      7:       <article class="media">
[d802e301-bbe2-4881-83ba-8e107adaa04e]      8:         <div class="media-left">
[d802e301-bbe2-4881-83ba-8e107adaa04e]      9:           <figure class="image is-256x256">
[d802e301-bbe2-4881-83ba-8e107adaa04e]     10:             <%= image_tag('95090365.jpeg') %>
[d802e301-bbe2-4881-83ba-8e107adaa04e]     11:           </figure>
[d802e301-bbe2-4881-83ba-8e107adaa04e]     12:         </div>
[d802e301-bbe2-4881-83ba-8e107adaa04e]     13:         <div class="media-content">
[d802e301-bbe2-4881-83ba-8e107adaa04e]   

我注意到人们设置的其他一些问题和答案

config.assets.compile = true 

修复此错误,但我在 Rails 文档中看到不推荐用于生产

此模式使用更多内存,性能比默认更差,不推荐使用" - https://guides.rubyonrails.org/asset_pipeline.html

我已经尝试了带 jpeg 后缀和不带 jpeg 后缀的 image_tag,两者都存在同样的问题。

有什么想法吗?提前致谢。

【问题讨论】:

  • 试试这个 image_tag('95090365.jpg')
  • 谢谢!是的,我在发布问题后就注意到了这一点,并且按照您发布的方式进行操作。我知道这会很微妙,(而且很愚蠢)。

标签: image asset-pipeline ruby-on-rails-6


【解决方案1】:
 <%= image_tag('95090365.jpeg') %>

需要改成

 <%= image_tag('95090365.jpg') %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-27
    • 2023-03-26
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多