开发者

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:

  1. The image_tag generates the HTML <img> tag, not <images>
  2. 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/
  3. image_tag gives you an alt attribute for proper accessibility.
  4. 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.
  5. 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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜