O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

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

JavaScriptHelper

Sometimes your Rails code will need to generate JavaScript, and not always in the context of RJS, as described in Chapter 16. These helper methods make it simpler to add basic JavaScript functionality to your pages, and remove the need to code some kinds of simple JavaScript by hand:

button_to_function

Creates a button that will call a JavaScript function using its onclick handler. It accepts a block of code, which works like RJS.

define_javascript_functions

Creates a link to Prototype and other JavaScript files, but is best avoided. Use javascript_include_tag instead.

escape_javascript

Reformats JavaScript containing carriage returns and quotes so that it can safely be put into HTML attribute values.

javascript_tag

Creates a script tag. Again, javascript_include_tag may be a better option.

link_to_function

Creates a link that will call a JavaScript function. Like button_to_function, it also can take a block that works like RJS.

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