DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Rails Image Tag Rollover Helper

05.16.2008
| 8442 views |
  • submit to reddit
        
<%= image_tag "/images/btn-off.jpg", :mouseover => "/images/btn-on.jpg" %>
which translates into...
<img alt="btn-off" onmouseout="this.src='/images/btn-off.jpg?1210954796'" 
onmouseover="this.src='/images/btn-on.jpg?1210954851'" 
src="/images/btn-off.jpg?1210954796" />
now with a link wrapped around the image tag
<%= link_to image_tag("/images/btn-off.jpg", :mouseover => "/images/btn-on.jpg"), :action => "perform" %>
and also as an image submit button for a form
<%= image_submit_tag "/images/btn-off.jpg", :mouseover => "/images/btn-on.jpg"%>