/  3
 
RJS templates are "just" another type of 
 view template
, made specifically for answering  Ajax requests. The code you write in an
.rjstemplate
is based around the page you will bechanging—the page that made the Ajax request(and therefore will be getting the response). Anythin you can do with JavaScript, youcan do with RJS.
rjs
demystified
a cheat sheet by amy hoy,
 www.slash7.com
tip!it?
   S   U   P   P   O   R   T   S   L   A   S   H   7
45-minute screencast video on RJS for only $9see it live! click:www.peepcode.com
 what is this RJS thing anyway?
*
R.J.S.,
acronym
Ruby JavaScript
 A templating tool, built inRuby, to output JavaScript.
synonym
,
amazing
Makes it almost utterly painless to craft sophisticated Ajax responses... with sexy results!
 
RJS techniques
insert new HTML anywhereremove HTMLchange DOM propertiesmove things aroundcreate special effectshide stuff show stuff take over the universe
********
 
rjs
demystified
a cheat sheet by amy hoy,
 www.slash7.com
loaded pagerailscontroller
here's how it works!
6
Javascript responseis detected, eval()'d—and run.
 start
triggered by anything youwant... forms, time, etc.e.g.: create a new post,or update a user's profile,or add a new transaction...RJS templatescan use regularviews &partials to addHTML to thepagethis javascript is whatcreates the changesto the pagethis makes the changes happen!
 
5
compiled JavaScriptis returned via Ajax
1
 your visitorloads a page
2
an ajax requestis made
3
the controllerreceives the requestand does its biz behind the scenes
4
the controllercompiles the RJStemplate it found
if@savedpage["new_expense_form"].reset page.visual_effect:blind_up,:new_expense page.insert_html:top,:expenses,:partial=>"expense" page.replace_html:total,"$#{@total}" page.delay(1)do page.visual_effect:highlight,"expense_#{@expense.id}" endelsepage.alert("Problemsavingexpense:#{@expense.errors.full_messages}") page.visual_effect:blind_up,:new_expense end
   a   s   a   m   p   l   e . . .
45-minute RJS screencastonly $9!peepcode.com
tip!it?
support Slash7!
The controller compiles this into JS & the response is sent as
Content‐Type:text/javascript

Share & Embed

More from this user

Add a Comment

Characters: ...

sagiveleft a comment

love it :) Thanks