O'Reilly logo

Professional Ruby on Rails™ by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.2. Easy JavaScript Integration

Inserting JavaScript into your application need not be a major hassle. Many developers have worked hard to create packages in JavaScript and Rails to allow you to insert significant behavior with very little fuss. This section describes three easy ways to insert some very helpful JavaScript.

8.2.1. Tooltips

Users have come to expect tooltips (or "those things that float on the screen" as some users call them). Although many browsers will automatically overlay the alternate (alt) text from an image or link over those elements, you may want to include a more elaborate floating-text behavior. Once you have an easy way to display tooltips, having a layer of content on your application that is invisible except during mouseover (when the mouse hovers over a screen element) becomes an irresistible way of increasing the amount of content on your pages.

What I'd like to do, by way of example, is build an extremely thin Ruby layer around a JavaScript package called Prototip. Prototip is a tooltip library written by Nick Stakenburg on top of the Prototype JavaScript library. As I write this, Prototip is at version 1.1, and can be picked up at www.nickstakenburg.com/projects/prototip/. The zip file will contain a .js file, which you should put in your public/javascripts folder, and a .css (Cascading Style Sheets) file, which goes in public/stylesheets. To make these files available, you need to load them in the layout header. In app/views/layouts/recipes.html.erb ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required