rails image_tag生成图片标签

image_tag(source, options={}) Link

Returns an HTML image tag for thesource. The source can be a full path or a file.

Options

You can add HTML attributes using theoptions. The options supports three additionalkeys for convenience and conformance:

  • :alt - If no alt text is given, the file name part of thesource is used (capitalized and without the extension)

  • :size - Supplied as "{Width}x{Height}" or "{Number}", so"30x45" becomes width="30" and height="45", and "50" becomes width="50" andheight="50". :size will be ignored if the value is not in thecorrect format.

Examples

image_tag("icon")
# => Icon
image_tag("icon.png")
# => Icon
image_tag("icon.png", size: "16x10", alt: "Edit Entry")
# => Edit Entry
image_tag("/icons/icon.gif", size: "16")
# => Icon
image_tag("/icons/icon.gif", height: '32', width: '32')
# => Icon
image_tag("/icons/icon.gif", class: "menu_icon")
# => Icon

你可能感兴趣的:(Rails)