RJS Reference
This reference section covers all of the methods supported by the
JavaScriptGenerator
as well as the
JavaScriptElementProxy
and the
JavaScriptCollectionProxy
classes. At the end of the
section, there is a list of Scriptaculous visual effects shipping with
Rails 1.1.
JavaScriptGenerator
The following is a list of all of the methods public methods
offered by the JavaScriptGenerator
. These methods are
called on the page
object in your RJS
templates.
Since RJS is all about generating JavaScript, it is nice to know what is going on behind the scenes. Knowing about the JavaScript that is generated makes it much easier to debug problems and create more complex applications. At some point, your RJS code may become too complex or there may be a task that you can't perform elegantly with RJS. If you understand how RJS generates JavaScript, you can easily port your code into a JavaScript library and use RJS to access your new JavaScript objects and methods.
Therefore, for all of the following definitions, I have placed the
JavaScript that the method generates after the Ruby code. The Ruby code
is marked with the comment # Ruby code
, and the
JavaScript is marked with // Generated
JavaScript
.
- <<(javascript)
Writes raw JavaScript to the page.
- [](id)
Returns a
JavaScriptElementProxy
for the DOM element with the specifiedid
. Methods can be called on the returned element. Multiple method calls can also be chained together.# Ruby code page['header'].show // Generated JavaScript $("header").show(); ...
Get RJS Templates for Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.