method
image_tag
v1.2.6 -
Show latest stable
- Class:
ActionView::Helpers::AssetTagHelper
image_tag(source, options = {})public
Returns an html image tag for the source. The source can be a full path or a file that exists in your public images directory. Note that specifying a filename without the extension is now deprecated in Rails. You can add html attributes using the options. The options supports two additional keys for convienence and conformance:
- :alt - If no alt text is given, the file name part of the source is used (capitalized and without the extension)
- :size - Supplied as "{Width}x{Height}", so "30x45" becomes width="30" and height="45". :size will be ignored if the value is not in the correct format.
image_tag("icon.png") # => <img src="/images/icon.png" alt="Icon" /> image_tag("icon.png", :size => "16x10", :alt => "Edit Entry") # => <img src="/images/icon.png" width="16" height="10" alt="Edit Entry" /> image_tag("/icons/icon.gif", :size => "16x16") # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
3Notes
watch out for urls with &
image_tag('x.com/aaa?a=1&b=2') = x.com/aaa?a=1&b=2
By images's sub dirctionary to img tag
===
image_tag("icons/edit.png") # =>
![]()
Specify your own template
You can specify you own template this way:
def notice
...
@template = "some_other_name.html.erb"
end