RailsConf – Unobtrusive Javascript

An extra session was added during Friday lunchtime, since Dan Webb’s Unobtrusive AJAX talk had been so popular on Thursday that not everyone who wanted to see it could get in.

Dan started off with some history of Javascript and how it got its bad name – but we think it is much better now. He then moved on to describe his method for making Javascript unobtrusive.

The first step is to get a working application with no Javascript, making sure it uses the correct HTML elements. Then we can start adding behaviour.

Some of the Rails javascript helpers are not well behaved, for example link_to_remote creates a link with no proper href. With a small change, this could create a link that works with or without Javascript. The Rails helpers also have a tendency to add lots of repetitive Javascript. Rails scaffolds also have links that have side-effects, e.g. the delete links – these should really use button_to.

Dan then introduced his UJS Rails Plugin which helps to add behaviour to pages in the style he advocates. It provides helper methods for attaching a given behaviour to elements via a CSS-like syntax, and also helpers for common kinds of behaviour we want to use.

He described it as ‘hijacking and enhancing’ the page.

As I’m a fan of JQuery, I was left wondering how using that or other javascript libraries would fit in. There is some feeling that Rails should be a bit more open for using different Javascript libraries – at the moment it is strongly tied to Prototype and Scriptaculous.

One Trackback

  1. By The Junction » jquerycamp on October 29, 2007 at 9:35 am

    […] Katz presented on using jQuery with Ruby web frameworks. In a lot of ways this was similar to the Unobtrusive Javascript presentation I have seen before, apart from the focus on jQuery for the javascript side. The […]

Post a Comment

Your email is never published nor shared. Required fields are marked *