The jQuery Way to apply behavior to a document is to add it unobtrusively via the $(document).ready() function, ideally in an external script file… unlike the Rails Way, which is to add behavior to individual elements via inline Javascript, using the built-in view helpers.
The markup generated by these helpers is obtrusive, and often repetitive. For example, using the built-in link_to_remote helper like this:
< % for post in @posts -%>
< %= link_to_remote post.title, :url => post_path(post) %>
< % end -%>
…generates this HTML:
<a onclick="new Ajax.Request(‘/posts/1′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 1</a>
<a onclick="new Ajax.Request(‘/posts/2′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 2</a>
<a onclick="new Ajax.Request(‘/posts/3′, {asynchronous:true, evalScripts:true}); return false;" href="#">Post 3</a>
… which is obtrusive, non-degradable and non-DRY. [Read more →]