I recently finished watching the RJS Peepcode Screencast and boy does it kick butt. Here’s my notes from watching it:
simply helpful plugin generates dom ids based on object’s: @thing.dom_id – more info
use link_to_function + rjs in the view to generate js without an ajax call. example:
link_to_function "Click Me", update_page {|page| page.alert "No postback!" }call custom js functions with page.call
page.call "my_func_name", param, anotherparam, etcconsider putting custom js functions that should be globally available in public/javascripts/application.js (this is included by javascript_include_tag :defaults)
page.select will fetch things by id or class
page.select('#tasks div a').each do |item| page.hide item enduse a method name in a string var as a function call
page.send 'method_name', paramreplace/replace_html for outside/inside an element with page.replace_html
page.replace_html 'task_totals', @task_totalsinsert your own custom js into the page with < <
page < < "my_js_method()"- or -
page < < %( my_js_method(); function some_other_func() { ... } ) - or -
page < < render :partial => "update_totals"
- or -
assign js vars with values from ruby with page.assign
page.assign 'task_totals', @task_totalskeep users informed of ajax calls during link_to_remote calls with :loading and :complete callbacks
link_to_remote "Click Me", :url => tasks_url(:action => 'hello'), :loading => "Element.show('loading_div')", :complete => "Element.hide('loading_div')"use rjs directly in the controller with render :update
render :update do |page| page.alert('whatever') endtest rjs with ARTS