我如何编写纯HTML,如< img> ERB中的标签? [英] How can I write pure HTML like <img> tag in ERB?
问题描述
我想用下面的代码替换<%= link_to image_tag(picture.png)
:< img src = /path/picture.png/>
在file.html.erb中
但是当我这样做时,错误,但没有图片显示在页面上。
所以,这里是我的回答:
默认情况下,rails将从 public
文件夹中提供所有资产。
您可以将图像放入资产/图像
文件夹中,并将其渲染为资产管道
。
但是,如果您想使用本地
< img src =/ path / picture.png/>
就像你在你的问题中提出的那样,那么你应该明白你在<$将相对于您的应用程序的 public
文件夹执行c $ c> src (src =/ path / picture.png)。 / p>
为了完成上述工作, picture.png
不会被放在 app / assets / images / picture.png
,但应放置在 public / path / picture.png
。
按照惯例,您需要将图片放入:
public / images / picture.png
因此,您应该使用 img
标签在您的视图中,如下所示:
< img src =/ images / picture.png/>
这对于您的问题可以正常工作。
I want to replace <%= link_to image_tag ("picture.png")
with something like this: <img src="/path/picture.png" />
in a file.html.erb
But when I do this, and it works without any error, but no picture shows up on the page.
So, here is my answer for you:
By default, rails will be serving all your assets from inside the public
folder.
You are able to put images in the assets/images
folder and render those because of the assets pipeline
.
However, if you want to use the native
<img src="/path/picture.png" />
like you asked in your question, then you should understand that the path you are specifying in your src
(src="/path/picture.png") will be taken relative to the public
folder of your application.
To make the above work then, picture.png
will not be placed in app/assets/images/picture.png
, but should be placed in public/path/picture.png
.
By convention though, you will want to place the picture in:
public/images/picture.png
So, you should then use the img
tag in your view as follow:
<img src="/images/picture.png" />
This will work fine for the purpose of your question.
这篇关于我如何编写纯HTML,如< img> ERB中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!