简体   繁体   English

Rails image_tag未关闭图像标记

[英]Rails image_tag not closing image tag

On a rails project I am using the image_tag to generate my image html elements. 在rails项目中,我使用image_tag生成我的图像html元素。

<%= image_tag("test.jpg", :alt => "test image") %>

is generating 正在产生

<img src="test.jpg" alt="test image">

This is happening throughout my entire rails project. 这在整个rails项目中都会发生。

Is there a setting somewhere that someone else set that is causing this? 是否有其他设置导致此设置的设置? How can I get rails to always close the image tag? 如何让rails始终关闭图像标签?

image_tag is implemented in terms of ActionView::Helpers::TagHelper.tag which takes an optional third parameter that says whether to close the tag or not (for XHTML compliance). image_tag是根据ActionView :: Helpers :: TagHelper.tag实现的 ,它采用可选的第三个参数来表示是否关闭标记(对于XHTML兼容性)。 By default it's off, but something is setting yours to true. 默认情况下它已关闭,但有些东西会将您设置为true。 Not sure where. 不知道在哪里。 You should be able to say 你应该可以说

 tag(:img, { :src => "test.jpg" }, false)

to force it. 迫使它。


Notice the use of :img instead of "img" . 注意使用:img而不是"img" :img is a symbol , that is basically a string that gets only created once. :img是一个符号 ,基本上是一个只创建一次的字符串。 A new string "img" on the other hand would get created every time you would call tag , therefore consuming a lot of memory. 另一方面,每次调用tag时都会创建一个新字符串"img" ,因此占用大量内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM