# Handling events: mouseover, etc

**URL:** <https://www.ruby-forum.com/t/handling-events-mouseover-etc/54606>\
**Category:** Rails\
**Created:** [March 9, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/handling-events-mouseover-etc/54606 "2006-03-09T20:20:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 9, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/handling-events-mouseover-etc/54606/1 "2006-03-09T20:20:56Z")

</div>

I’m having a hard time figuring out how to handle mouseover events w/  
Ruby on Rails (esp. whether Javascript takes over, or the Controller  
should be used).

I’m currently trying to create a simple mouseover info box showing the  
definition, and some other information, when certain words are  
moused-over.

Say I have an array of Word objects that have 1) word name 2) definition  
3) latin origin.  
From my controller, I create a list of words by rendering partial (to  
the div element “word\_list”) the collection (using a \_word.rhtml  
partial)

In the \_word.rhtml partial:  
How do I set up a trigger for the onmouse over using link\_to (assuming  
that’s the best func to use)?  
How do I get the Word object definition, etc. into the (currently  
hidden) info box when someone does mouseover? Is it best done through  
the controller or though a call to a Javascript function?

Finally, where is the positioning of the info box set? (so it appears  
next to the word it is defining)

I hope this is clear enough and thank you so very much in advance!

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 9, 2006, 8:50pm UTC](https://www.ruby-forum.com/t/handling-events-mouseover-etc/54606/2 "2006-03-09T20:50:24Z")

</div>

On 3/9/06, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m having a hard time figuring out how to handle mouseover events w/ Ruby  
> on Rails (esp. whether Javascript takes over, or the Controller should be  
> used).

You should (you have to, really) use JavaScript for anything on the  
client -  
any browser-side event = JavaScript. But the data (the definition, or  
whatever) can come from the server (Rails) if you want it to - that’s up  
to  
you.

I think the approach I’d take for something like this, would be to load  
up a  
bunch of divs:

Set up your stylesheet to hide these divs, then use a onmouseover event  
to  
turn the on and position them.

– Joshua

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 9, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/handling-events-mouseover-etc/54606/3 "2006-03-09T21:02:41Z")

</div>

My solution to this would be to wrap the relevant words in a  
‘content\_tag’ call

\<%= content\_tag(‘span’,‘word’, “title”=\>“definition”) %\>

This should result in a tooltip with the definition on most browsers.

\_Kevin
