You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails仅加载部分资产,部分图片无法加载问题求助

Rails项目部分图片无法加载,重命名后恢复的问题

问题现象

  • 项目app/assets/images目录下存在2年以上的部分图片突然无法加载,仅重命名"异常"文件即可正常访问
  • 页面通过https://mysite/assets/file_name.png路径加载图片,其中:
    • 可正常加载的文件:
      • app/assets/images/severity_icons/medium-impact.png
      • app/assets/images/severity_icons/medium-top-vulns.png
    • 无法加载的文件:
      • app/assets/images/severity_icons/medium-recommendation.png
      • app/assets/images/severity_icons/medium-reproduction.png

服务器文件信息

服务器上目标文件的权限及大小信息:

root@670e1c54cdd6:/myapp/app/assets/images/severity_icons$ ls -l medium*
-rw-r--r-- 1 root root 8831 Nov  6 03:03 medium-impact.png
-rw-r--r-- 1 root root 9321 Nov  6 03:03 medium-recommendation.png
-rw-r--r-- 1 root root 9468 Nov  6 03:03 medium-reproduction.png
-rw-r--r-- 1 root root 9762 Nov  6 03:03 medium-top-vulns.png

错误日志示例

以medium-recommendation.png为例,访问时日志输出路由错误:

I, [2022-11-06T16:27:17.195355 #191]  INFO -- : [8a73e9a4-fbc7-4c30-87a0-f7f35959afcd] Started GET "/assets/medium-recommendation.png" for [obfuscated IP] at 2022-11-06 16:27:17 +0000
F, [2022-11-06T16:27:17.206898 #191] FATAL -- : [8a73e9a4-fbc7-4c30-87a0-f7f35959afcd]
[8a73e9a4-fbc7-4c30-87a0-f7f35959afcd] ActionController::RoutingError (No route matches [GET] "/assets/medium-recommendation.png"): 

验证结果

  • 异常文件与正常文件在同一目录,且已一同执行rake assets:precompile预编译,但问题未解决
  • 将medium-recommendation.png重命名为medium-r.png后,可正常访问:
➜  ~ curl https://mysite/assets/medium-recommendation.png
<html><body>You are being <a href="https://mysite/">redirected</a>.</body></html>%
➜  ~ curl https://mysite/assets/medium-r.png
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.

内容的提问来源于stack exchange,提问作者LewlSauce

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:16:06