Rails 4 不是 image_url 的正确路径 [英] Rails 4 not right path for image_url
问题描述
因此,我在 Rails 项目上的下一个问题如下:我正在使用资产管道来为我的资产提供服务.现在我想将 inline css 包含到带有背景图像的视图中.由于资产管道,我只能使用 rails 从地面提供的帮助程序.但问题是,每个助手(除了 image_tag
都提供错误的输出).
So, my next problem on a rails project is the following: I am using the asset pipeline to serve my assets. Now I want to include inline css into a view with a background image. because of the asset pipeline I am just able to use the helpers that rails offers from ground. But the problem is, that every helper (except image_tag
is delivering the wrong output).
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!
是的, 对我没有帮助.以及我发现的有关此主题的所有其他问题.
Yeah, that didn't help me. And also all other questions I found about this topic.
很高兴知道这有什么问题.谢谢!
Would be nice to know what the issue is with this. Thanks!
推荐答案
我自己回答了另一个问题.
Another question answered myself.
我在 image_path
帮助器中有错误的路径.因此,如果您丢失了图像(资产管道无法找到该图像,则帮助程序将退回到 /images
路径.
I had the wrong path in the image_path
helper. So, if you have a missing image (that cannot be found by the asset pipeline, the helper is falling back to the /images
path.
让我们想象一下我想在我的文档中包含 ph/image-1.png
的路径.image_path('ph/image-1.png')
会将正确的目录与路径放在一起.否则,如果您打算使用 image_path('image-1.png')
它将使用您要使用的图像前面的 /images
目录.但是这个是找不到的.这是我的错.
Let's imaging I want to include a path of ph/image-1.png
into my document. image_path('ph/image-1.png')
will put the right directory with the path. Otherwise, if you are going to use image_path('image-1.png')
it will use the /images
directory in front of the image you are going to use. But this cannot be found. This was my fault.
最后总结一下:
image_path('ph/image-1.png') # => /assets/ph/image-1.png
image_path('image-1.png') # => /images/image-1.png
这篇关于Rails 4 不是 image_url 的正确路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!