rjstemplates
RJS Templates
RJS Templates
A new template in Rails 1.1
RJS is:
· A means to Ajaxify your application without
writing JavaScript.
· The most lacking feature from Rails 1.0 for
front-end developers (well, maybe not that bold)
What does it do?
· Not invoked directly · Called through Ajax (xmlHttpRequest)
requests browser
· Returns JavaScript to be executed in the
Rails 1.1
· Added new helper: JavaScriptGenerator · New methods in Prototype.js, most notably:
$$()
(aka: getElementsBySelector())
· New object available to generate JavaScript: page · Become familiar with available methods:
JavaScriptGenerator Docs
First thing
· Upgrade to Rails 1.1.1: gem install rails --include-dependencies
rake rails:update
· Already running 1.1? Update to 1.1.1 for lots
of minor fixes, including JavaScript fixes
· Start playing with RJS templates
Usage
· RJS templates go where all templates
normally go, in the view.
· Just like RXML, except with an RJS extension · No need to use <% ... %>
RJS code is small
· Most of the time, creating an RJS template is
overkill (and overly tedious). existing view. follow)
· RJS isn't exactly a view, but manipulating an · Put it in the controller instead (example to
Simple RJS Example
· Updating a page element in an RJS template: page.replace_html `element_id', · From within an action (no RJS file needed): render :update do |page|
page.replace_html `element_id', `New HTML or Text' end `New HTML or Text'