The image_tag
is rails default helper method for loading the images in your application. It comes with various options inside the tags and the syntax is as follows;
image_tag(source, options = {}) public
Options
You can add HTML attributes using the options. The options supports three additional keys for convenience 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.
:mouseover
- Set an alternate image to be used when the onmouseover
event is fired, and sets the original image to be replaced
onmouseout. This can be used to implement an easy image toggle
that fires on onmouseover.
These are the options which comes with it by default and no worries to write and extra css as you have asked and explained using css example as;
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
Examples
1st
image_tag("icon.png", :size => "16x10", :alt => "Edit Entry")
HTML Output
<img src="/images/icon.png" width="16" height="10" alt="Edit Entry" />
2nd
image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))
HTML Output
<img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" />
Hope this helps! :-)