【问题标题】:How to add a new image to a rails project?如何将新图像添加到 Rails 项目?
【发布时间】:2012-04-28 08:34:18
【问题描述】:

我正在开发 Rails 应用程序的前端部分。我必须添加一些图像,所以我将这些图像添加到 app/assets/images 目录中。

我可以通过 /assets/[图像名称] 访问应用附带的图像,但我无法访问我的新图像。我试过了

/assets/images/[image name]
/assets/[image name]
/[image name]
/images/[image name]

看起来背后有一个缓存系统,或者我做错了什么。

请给我建议。

谢谢, 月亮

【问题讨论】:

    标签: ruby-on-rails caching assets


    【解决方案1】:

    您应该始终使用 image_tagasset_path 帮助程序来计算命名资产的路径 - 请参阅资产管道指南中的 Linking Assets

    如果您使用默认的简单的基于文件的 Rails 缓存,也可以尝试rake tmp:clear,以确保没有任何内容被错误地缓存。

    【讨论】:

      【解决方案2】:

      试试:

      <%= image_tag "yourfilename.png" %>
      

      【讨论】:

      • 另外,我将图像移至供应商/资产/图像。当我的图像位于 app/assets/images 中时,我遇到了同样的问题。希望对您有所帮助!
      猜你喜欢
      • 1970-01-01
      • 2012-04-18
      • 2013-02-10
      • 2016-02-23
      • 2020-03-05
      • 2013-04-17
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多