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:
Find

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
an :alt option in the hash there is no :class option.

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 C.

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

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

On Nov 25, 2007 12:49 AM, William P. [email protected] 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


Mark Van H., Partner / Software Developer
[email protected], (616) 706-6842
Mutually Human Software, http://mutuallyhuman.com

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