gpt4 book ai didi

css - Rails 4 不是 image_url 的正确路径

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:20 25 4
gpt4 key购买 nike

因此,我在 Rails 元素中遇到的下一个问题如下:我正在使用 Assets 管道来为我的 Assets 提供服务。现在我想将 inline css 包含到带有背景图片的 View 中。由于 Assets 管道,我只能使用 Rails 从地面提供的助手。但问题是,每个助手(image_tag 除外)都提供了错误的输出。

image_url('work-1.png')         # => /images/work-1.png
image_path('work-1.png') # => /images/work-1.png
asset_url('work-1.png') # => /work-1.png
asset_path('work-1.png') # => /work-1.png
image_tag('work-1.png') # => <img ..........> # Only right tag!

是的,that没有帮助我。以及我发现的有关此主题的所有其他问题。

很高兴知道这是什么问题。谢谢!

最佳答案

image_tag helper 是您列表中唯一会实际生成 html 标记的方法。

image_url助手实际使用 image_path计算图像完整路径的助手(例如 http://www.example.com/image/image.png)

image_path助手生成图像的相对路径(例如/images/foo.png)

image_tag输出

image_tag("icon") # => <img alt="Icon" src="/assets/icon" />
image_tag("icon.png") # => <img alt="Icon" src="/assets/icon.png" />
image_tag("icon.png", size: "16x10", alt: "Edit Entry") # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
image_tag("/icons/icon.gif", size: "16") # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
image_tag("/icons/icon.gif", height: '32', width: '32') # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
image_tag("/icons/icon.gif", class: "menu_icon") # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />

image_path 输出

image_path("edit")                                         # => "/images/edit"
image_path("edit.png") # => "/images/edit.png"
image_path("icons/edit.png") # => "/images/icons/edit.png"
image_path("/icons/edit.png") # => "/icons/edit.png"
image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"

关于css - Rails 4 不是 image_url 的正确路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27630074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com