【问题标题】:Rails image not found未找到 Rails 图像
【发布时间】:2020-11-09 10:54:02
【问题描述】:

我已尝试搜索我的问题,但没有一个解决方案有效。我非常困惑为什么当我在 localhost:3000 上运行我的网站时我的 .png 没有显示。

这是我的文件结构/文件夹和robot.png的s​​rc路径 screenshot

【问题讨论】:

  • 查看用于执行此操作的代码会有所帮助

标签: ruby-on-rails image localhost


【解决方案1】:

我最终将它保存在新目录 assets/images/logos/robot.png 并使用<%= image_tag ("logos/robot.png") %>,它终于成功了!

【讨论】:

    【解决方案2】:

    您应该移动app/assets/images 中的所有图像,然后使用<%= asset_path 'image_name.png' %>

    这是标准解决方案

    【讨论】:

    • 感谢您的回答,但它并没有解决我的问题。页面现在显示:/assets/robot-21929452ab382079d8f9c28763539584774757a809a84f9d4d6e0dff016e83a8.png 而不是实际的 png
    • <img src="<%= asset_path 'image_name.png' %>"> 或 <%= image_tag "image_name.png" %>
    【解决方案3】:

    你可以这样做:

    <%= image_tag ("images/robot.png") %>
    

    image_tag 会自动在路径的开头添加资源

    查看Image Tag 获取文档。

    【讨论】:

    • 谢谢!不幸的是,我收到The asset "images/robot.png" is not present in the asset pipeline. 非常烦人,因为我知道 png 在那里......
    猜你喜欢
    • 2017-05-18
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 2019-01-25
    • 2020-10-15
    • 2021-03-18
    • 1970-01-01
    相关资源
    最近更新 更多