Tuesday, March 22, 2005

Rails 0.11.0: Ajax, Pagination, Non-vhost, Incoming mail

Posted by admin

With the inclusion of Ajax helpers in Rails 0.11.0, we’ve addressed the most important concern holding back large scale Ajax use: Writing DHTML by hand. Manipulating the DOM by hand is a labor-intensive and error-prone process rife with frustration and cross-browser compatibility. With the Ajax support in Rails, writing manual Javascript/DHTML is (almost) a thing of the past.

Through a handful of helper tags, we’ve exposed an approach that relies on a bare minimum of support on the client-side (XMLHttpRequest and innerHTML) while offloading the generation of page fragments to familiar constructs like ERb and Builder templates. This means that you’ll build your Ajax integration using all the tools you’re familiar with and safely let the Javascript/DOM magic be off-loaded to the Rails helper and library.

Sam Stephenson (hire this guy!) has been the architect behind transforming my meager Javascript attempts into a fully object-oriented library that the Rails helper calls to do its dirty work. He has also done a video demonstrating how he can turn a create form into Ajax in just a few minutes. While this may appear a bit complicated, its mostly because the application Sam’s integrating with lets the controller generate the URL, which normally isn’t the case.

While the Ajax support is certainly the star of this release, we have much more. Another Sam Stephenson goodie is Pagination support, which lets you seamlessly spread the results of a list across multiple pages by combining controller-side and view-side support for pages and navigation.

Also of note is that Rails applications no longer require their own virtual host to be easy to setup. It’s now possible to symlink the public directory from underneath an existing hierarchy, so your application can live under hieraki in /community/hieraki. This should make it considerably easier to install and distribute applications that need to live on shared servers. If you want to make your own application vhost agnostic, have a look at the AssetTagHelper that’ll automatically create the proper paths for images, stylesheets, and the likes.

The Action Mailer gained inbound capabilities in this release. By implementing the receive(email) method, you can target your Action Mailer from fx postfix and have it process incoming emails. We’ve even enhanced TMail to make it easy to process international emails (auto converting to UTF-8) and handling file attachments. See the example in the README and checkout the Howto.

On top of all that there’s a new script/runner for making it easy to call your Rails domain model from CRON, there’s a new Flash module, there’s database indifferent limit/offset, and a truckload of fixes, enhancements, and tweaks.

See all the changes in the changelogs for Rails, Active Record, Action Pack, Active Support, Action Mailer, and Action Web Service.

Updating: If you’re coming from Rails 0.10.1, just run rails . --skip in the root of your application to get the new files. You shouldn’t need to change any code. You will need to clear out all your sessions, though, because of the Flash module upgrade!