Wednesday, July 6th, 2005

Rails 0.13: Ajax in Rails Update

Category: Ruby

The Rails team have churned out a bunch of new features and fixes for the 0.13 release: performance improvements, easier caching, named routes, and the additions to the render() method. There is also a lot of new Ajaxian components in there:

Ajax: Visual effects, drag’n’drop, sortable lists, auto-completing text fields
Thomas Fuchs is the latest member of the Rails core contributor group and his amazing set of Javascript magic, entitled script.aculo.us, has been integrated in this release.

It adds a completely rewritten visual effects engine, drag-and-drop capability including sortable lists, and autocompleting text fields to Rails. All building on top of Prototype, the foundation for Ajax in Rails, which has also received a spiffy upgrade by Sam Stephenson.

Hand in hand with the Javascript files is a fresh batch of helper methods that enables to skip the process of writing any Javascript yourself. The new auto_complete_for macro is one of these helpers and it makes adding Google Suggest style auto-completing text fields effortless, as does sortable_element for sortable lists and floats and draggable_element and it’s counterpart drop_receiving_element for drag-and-drop. Try out the live demos and see source code.

We also have Ajaxified progress indicators for file uploads in as an experimental feature in this release. It makes for a much more user-friendly experience uploading large files. See the demo. It’s experimental nature means that it only works on Apache, lighttpd 1.4.x, and only in some environments. Consider it a preview of really cool tech. You need to include ActionController::Base.enable_upload_progress in your environment.rb file to turn it on.

We’ve additionally added support for graceful error handling of Ajax calls:

link_to_remote( "test", :url => { :action =>"faulty" }, :update => { :success =>"good", :failure =>"bad" }, 403 =>"alert('Forbidden- got ya!')", 404 =>"alert('Nothing there...?')", :failure =>"alert('Unkown error ' + request.status)")

And if you want to perform multiple document updates on a single Ajax call, there’s now the lovely JavascriptHelper#update_element_function, which can be used to generate a stacked return.

View the demos:

Posted by Dion Almaer at 5:20 pm
Comment here

+++--
3.4 rating from 7 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.