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_functionCreates a button that will call a JavaScript function using its
onclickhandler. It accepts a block of code, which works like RJS.define_javascript_functionsCreates a link to Prototype and other JavaScript files, but is best avoided. Use
javascript_include_taginstead.escape_javascriptReformats JavaScript containing carriage returns and quotes so that it can safely be put into HTML attribute values.
javascript_tagCreates a
scripttag. Again,javascript_include_tagmay be a better option.link_to_functionCreates a link that will call a JavaScript function. Like
button_to_function, it also can take a block that works like RJS.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access