image_tag is missing "class=" attribute--how can I replace javscript behavior?

(Apologies if a previous message was posted inadvertently. My finger slipped on the enter key.)

While converting a static HTML prototype to Rails I changed a bunch of alinks from this: <a href="find.html"><img src='/images/findTab.jpg' alt="Find" class="rollover" /></a>

to the more Railsesque construction shown here: <%= link_to(image_tag('findTab.jpg', :alt => 'Find an item'), :action => 'Find') %>

Sharp-eyed readers will note that the class="rollover" attribute, which was provided by Javascript, is now gone. While image_tag has

How can I restore the class="rollover" attribute if image_tag doesn't support it, or at least get the rollover behavior back somehow?

Thank you.

Tom Campbell

link_to takes a third argument that is a hash of html options:

<%= link_to(image_tag('findTab.jpg', :alt => 'Find an item'), {:action=> 'Find'}, :class => 'rollover') %>

-Bill

Tom Campbell wrote:

Oops, I just noticed that you are applying that class to the image not the link, but this will work:

<%= link_to(image_tag('findTab.jpg', :alt => 'Find an item', :class => 'rollover'), :action=> 'Find') %>

-Bill

William Pratt wrote:

link_to takes a third argument that is a hash of html options:

<%= link_to(image_tag(‘findTab.jpg’, :alt => ‘Find an item’), {:action=> ‘Find’}, :class => ‘rollover’) %>

However, that adds the class to the anchor tag, not the image…

Sharp-eyed readers will note that the class=“rollover” attribute, which was provided by Javascript, is now gone. While image_tag has an :alt option in the hash there is no :class option.

Actually, any option you pass to image_tag will be in the generated html tag as an attribute:

<%= link_to(image_tag(‘findTab.jpg’, :alt => ‘Find an item’, :class => ‘rollover’), :action=> ‘Find’) %>

Mark

Right, hence my second post 10 seconds after my first post:

Oops, I just noticed that you are applying that class to the image not the link, but this will work:

<%= link_to(image_tag('findTab.jpg', :alt => 'Find an item', :class => 'rollover'), :action=> 'Find') %>

-Bill

Mark Van Holstyn wrote: