我怎样才能写出像 <img> 这样的纯 HTML?在 ERB 中标记? [英] How can I write pure HTML like <img> tag in ERB?

查看:62
本文介绍了我怎样才能写出像 <img> 这样的纯 HTML?在 ERB 中标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用这样的东西替换 <%= link_to image_tag ("picture.png"):<img src="/path/picture.png"/> 在一个文件.html.erb

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:

默认情况下,rails 将从 public 文件夹中提供所有资源.

By default, rails will be serving all your assets from inside the public folder.

您可以将图像放在 assets/images 文件夹中并渲染这些图像,因为 assets pipeline.

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" />

就像您在问题中提出的那样,那么您应该了解您在 src(src="/path/picture.png") 中指定的路径将相对于 public 应用程序文件夹.

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.

为了使上述工作,picture.png不会放在app/assets/images/picture.png中,而应该放在中public/path/picture.png.

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

因此,您应该在视图中使用 img 标签,如下所示:

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.

这篇关于我怎样才能写出像 &amp;lt;img&gt; 这样的纯 HTML?在 ERB 中标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆