method

image_tag

image_tag(source, options = {})
public

Returns an image tag converting the options into html options on the tag, but with these special cases:

  • :alt - If no alt text is given, the file name part of the src is used (capitalized and without the extension)
  • :size - Supplied as "XxY", so "30x45" becomes width="30" and height="45"

The src can be supplied as a…

  • full path, like "/my_images/image.gif"
  • file name, like "rss.gif", that gets expanded to "/images/rss.gif"
  • file name without extension, like "logo", that gets expanded to "/images/logo.png"

3Notes

watch out for urls with &

grosser · Jul 10, 2008

image_tag('x.com/aaa?a=1&b=2') = x.com/aaa?a=1&b=2

By images's sub dirctionary to img tag

RobinWu · Oct 31, 2008

=== image_tag("icons/edit.png") # => edit

Specify your own template

Ramon · Mar 10, 2010

You can specify you own template this way:

def notice
...
@template = "some_other_name.html.erb"
end