On a rails project I am using the image_tag to generate my image html elements.
<%= image_tag("test.jpg", :alt => "test image") %>
is generating
<img src="test.jpg" alt="test image">
This is happening throughout my entire rails project.
Is there a setting somewhere that someone else set that is causing this?
How can I get rails to always close the image tag?
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). By default it’s off, but something is setting yours to true. Not sure where. You should be able to say
to force it.
Notice the use of
:imginstead of"img".:imgis a symbol, that is basically a string that gets only created once. A new string"img"on the other hand would get created every time you would calltag, therefore consuming a lot of memory.