Ruby, Rails and RJS
So, today I learned about RJS for Rails… RJS, or Remote Javascript, is a method which allows you to write complex AJAX scripts using Ruby syntax etc. Using RJS templates, it is possible to create extensive effects.
Now Rails has for a long time naturally includes some built-in functionality for AJAX, via the PrototypeHelper and ScriptaculousHelper libraries. Unfortunately, these two helpers would only allow one element in the DOM to be updated in an AJAX operation. That did not suit for what I wanted to do. Luckily, since Rails 1.0, RJS has been including. In addition to providing a simpler way to write AJAX functionality into your project, it also allows you to modify as many parts of the DOM as you wish per AJAX operation.
Of course, there doesn’t seem to be any good tutorials concerning RJS on the Internet. After looking for a while, RyanB from the Rails Forum suggested purchasing RJS Templates for Rails from O’Reilly. This is a great book - it comes as a PDF, and is only 60 pages or so, but is jam-packed with information on RJS, with code examples, and everything.
Because of this, I have been able to start implementing some AJAX functionality on a project for my employer. The visual effects from script.aculo.us are pretty cool, but the real benefits come from the increase of useability for the end-user. No longer does a user have to wait for page reloads etc. everytime he changes a vaue on the page. Plus, it is simple to link the AJAX pieces into your database, yielding an extremely ‘live’ page.
So, the moral of the story is, if you utilize Rails together with AJAX in any way, look into RJS - it can and will save you tons of time and energy, while vastly improcing your site design and useability!
Share This