Using jQuery in Rails apps
jQuery is an alternative to the Prototype JavaScript library that is gaining some real traction these days.
jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.
jQuery also sports an elegant model of method chaining where almost all methods return an instance of the object they are called on, this means you do do stuff like:
$("p.surprise").addClass("ohmy").show("slow");
The only problem is I love using Rails which has many helper methods that make using Ajax really easy which use the Prototype JS library, so ncluding jQuery as well as Prototype is not only a pain it also means i’m doubling the amount of javascript i ship with each page.
Fortunatly the problem has been solved via a cool rails plugin called jrails.
jrails is easy to install (script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails) and replaces all the calls to Prototype with calls to jQeury allowing you to remove prototype from your application without loosing any of the rails magic.
