<?xml version="1.0" encoding="UTF-8"?>
<cheatsheet>
  <created-at type="datetime">2009-01-28T23:50:49Z</created-at>
  <description>Element Properties:-
page[:my_div].show| visible
page[:my_div].hide| invisible
page[:my_div].toggle| alternate show and hide
page[:my_div].remove| remove
page[:my_div].add_class_name :pink| css class added
page[:my_div].remove_class_name :pink| css class removed
page[:my_div].set_style :width =&gt; '500px'| css property width added
page[:my_div].visual_effect :highlight. :blind_down. :duration =&gt; 5
page[:my_div].visual_effect(:highlight) .remove_class_name(:green)|scriptaculous methods can be chained 
page[:my_field][:value] = 'new value'| field value set
page[:my_div][:style][:color] = 'red'
Element Content Manipulation:-
page[:my_div].replace_html &quot;New Text&quot;| replaces html
page[:my_div].replace &quot;New Text&quot;| replaces entire div
page[:my_div].replace_html :partial =&gt; &quot;my_div&quot;| replaces div content with partial output
page[:my_div].replace :partial =&gt; &quot;my_div&quot;| replaces entire div with partial output
page[:my_div].reload| like replace with partial my_div
Element Collection Manipulation:-
page.select('table tr').first
page.select('table tr').last.hide
page.select('table tr').each do \item\ item.visual_effect :highlight end
page.select('table tr td').invoke('upcase')| invokes upercase method on every td
page.select('table td td').pluck('results'.'innerHTML')|plucked and stored in javascript variable results
collect/map| TBA
detect/find| TBA
select/find_all| TBA
reject
partition
min and max
all and any
inject
zip
sort_by
Javascript Generator Methods:-
page.hide :div1. :div2
page.show :div1. :div2
page.toggle :div1. :div2
page.remove :div1. :div2
page.insert_html [:bottom :top :before :after]| :my_div. 'new text'
Misc Page Methods:-
page.redirect_to url_for(:action =&gt; 'index')|redirect the browser
page.redirect_to some_url| redirect
page.delay(5) { page[:my_div].visual_effect :fade }| execute block after 5 seconds
page.draggable :my_div| make my_div draggable
page.drop_receiving :basket. :url =&gt; {:action =&gt; 'delete'}|basket can receive dragged elements
page.sortable :todo. :url =&gt; { :action =&gt; 'change_order' }|  make todo list sortable
page &lt;&lt; &quot;alert('hello')&quot;| arbitrary javascript added to page
page.assign :greeting. 'hello'| variable greeting assigned hello
page.call :alert. &quot;hello&quot;| call javascript alert with argument &quot;hello&quot;
page.form.reset :my_form| reset my_form (id or name?)
page.field.focus :my_field| reset my_field
class proxies| TBA
Helpers:-
&lt;%= link_to_remote &quot;Alert&quot;. :url =&gt; {:action =&gt; &quot;do&quot;} %&gt;| on click make ajax request
&lt;%= link_to_function &quot;update_page&quot; do \page\ page.alert &quot;Hello&quot; end %&gt;| rjs without ajax
&lt;%= link_to_function &quot;update&quot; do \page\ page.my_helper end %&gt;
&lt;%= link_to_remote &quot;check&quot;. :failure =&gt; update_page { \page\ page.handle_failure }| can be used in places whereever javascript is needed
&lt;%= update_page_tag {\page\ page.my_helper} %&gt;| same as update_page except renders with script tag
other:-
render :text =&gt; &quot;text&quot;. :content_type =&gt; &quot;text/javascript&quot;| action sends text to ajax request
render :update do \page\ page.alert &quot;hello&quot; end| action sends js
page[:my_div].set_style :width =&gt; '500px'| rendered as $$(&quot;my_div&quot;).setStyle({&quot;width&quot;:&quot;500px&quot;})
Element.toggleClassName(element. className)| custom method called as page[:my_div].toggle_class_name 'green'
Steps to use observe_field:-
If we use Ajax check box or select box, do the following steps
Required:
observe_field id should be in this format|&quot;div id to update_action for that&quot;
url:| :my_action
update:| :my_div
with:| observe_field 'id' or 'value' or 'id+value'
Action:| :my_action
Partial view:|:my_div

Eg for check box:|check_box &quot;my_div&quot;, &quot;my_action&quot;
Eg for observe_field:|observe_field(:my_div_my_action,:update =&gt; :my_div,:with =&gt; ':my_div_my_action',:url =&gt; { :action =&gt; :my_action})
						
  
References:
http://www.digitalni.com.au/articles/rails_ajax_divs
</description>
  <id type="integer">12</id>
  <title>Ajax on Rails</title>
  <updated-at type="datetime">2009-02-09T08:46:29Z</updated-at>
</cheatsheet>
