Monday, June 13, 2005

AJAX and Ruby on Rails

O'Reilly has a nice aricle on Ruby on Rails and AJAX, the hot new DHTML/remote scripting "why didn't we do this before?" phenomenon.

Apparantly, the new Pragmatic Programmers book on development with Rails will do a good job covering remote scripting/AJAX. I'll be getting this when it comes out in July.

The problem with DHTML and remote scripting has always been the requirement to hand-craft each page in much the same way as one might hand craft a chair. The difference is that a chair lasts a lifetime while a page lasts until you need to refactor it. This is why Flex is so hot; it lets you do neat dynamic and remote-calling things with an easy-to-use API. We'll really be getting somewhere if frameworks like Rails can become easy-to-use APIs whereby you only need to worry about what you need to call on the client side and what you need to send on the server side and not about the plumbing.

I'll be building a site this summer using Rails and will most likely now be adding some AJAX behaviours to the mix.

Here's a snippet from the article that sets up a live-updatable search list:

<%= text_field_tag :searchtext %>
<%= observe_field(:searchtext, :frequency => 0.25,
:update => :search_hits,
:url => { :action => :live_search }) %>

<p>Search Results:</p>
<div id="search_hits"></div>

The great thing about this is that the plumbing is hidden. Set up the structure and the actions, implement the back-end, and voila!