Why isn't my image tag working?
What is the different with
<images src="http://localhost:3000/images/logo_general.png">
and
<%= image_tag("logo_general.png") %>
Why am I 开发者_如何学JAVAhaving problems loading images using the first way?
Probably because the correct tag to use is
<img>
And not
<images>
There are several differences:
- The image_tag generates the HTML
<img>
tag, not<images>
- The source path is based on your asset host and asset path, so images don't break if they change. The default is relative to root, e.g. /images/
- image_tag gives you an alt attribute for proper accessibility.
- In development mode, it adds a random number to the image as a convenience to prevent the browser from using a cached image in case you change it.
- image_tag properly closes the tag. with
/>
.
You can try it out in the Rails Console.
image_tag("logo_general.png")
=> <img alt="Logo_general" src="/images/logo_general.png?1230601161" />
精彩评论