faded picture of luke
a semi-random photo | click for the full photo gallery
click to browse photos
homepage navigation

Luke Melia

January 9, 2006

Debugging your RJS calls in Rails

RJS templates aka JavascriptGenerator templates are a powerful tool in the latest versions of the Ruby on Rails framework that has been a real mind-bender for me. In a nutshell, they give you the ability to respond to an AJAX request by telling the page to execute a sequence of javascript commands. And the javascript can be generated using Rails' excellent helper classes that build on prototype.js and scriptaculous.

Turns out they can be a little hairy to debug. When I had some bad javascript, I wasn't seeing it captured in the FireFox console. The javascript would just silently fail to execute if there was invalid javascript syntax. Rails Weenie to the rescue:

Drop this into the bottom of your layout:

HTML:
  1. <div id="debug">
  2. </div>
  3. <script type="text/javascript">
  4.     Ajax.Responders.register({
  5.     // log the beginning of the requests
  6.     onCreate: function(request, transport) {
  7.     new Insertion.Bottom('debug', '<p><strong>[' + new Date().toString() + '] accessing ' + request.url + '</strong></p>')
  8.     },
  9.    
  10.     // log the completion of the requests
  11.     onComplete: function(request, transport) {
  12.     new Insertion.Bottom('debug',
  13.     '<p><strong>http status: ' + transport.status + '</strong></p>' +
  14.     '<pre>' + transport.responseText.escapeHTML() + '</pre>')
  15.     }
  16.     });
  17. </script>

This let's you see what ajax calls are being made and what javascript is being sent in response. Notice your boneheaded error, fix it, and smile!

January 5, 2006

CruiseControl.NET and FxCop

Quoted in Software Development Times

LukeMelia.com created 1999. ··· Luke Melia created 1976. ··· Live With Passion!
Luke Melia on software development freelance web development how to contact me Luke Melia, Software Developer letters and more from my travels photo gallery personal philosophy