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

I integrated FxCop with CruiseControl.NET and NAnt for a .NET 2.0 project today. A couple of notes that might be useful for anyone doing the same.

I copied the fxcop directory from the VS.NET folder (inside of Team Tools, I think) into my tools directory, so it will be checked in with my project.

Then I added the a target like this to my nant build script:

XML:
  1. <target name="analyze" depends="your-target-that-builds-assemblies" description="Run FxCop against built assemblies">
  2.                        
  3.                         <property name="fxcop.results.file" value="${build.dir}\fxcop-results.xml" />
  4.                         <exec program="tools\fxcop\FxCopCmd.exe" failonerror="false">
  5.                                     <arg value="/file:${build.dir}\*.dll" />
  6.                                     <arg value="/file:${build.dir}\path\to\another\assembly\to\analyze.dll" />
  7.                                     <arg value="/forceoutput" /> <!-- create output even if no violations are found -->
  8.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1300" /> <!-- an example of how to suppress rules -->
  9.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1301" />
  10.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1302" />
  11.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1303" />
  12.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1304" />
  13.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1305" />
  14.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1306" />
  15.                                     <arg value="/out:${build.dir}\fxcop-results.xml"" />
  16.                         </exec>
  17.   </target>

And in your ccnet.config file, make sure you are merging the results file. Update your dashboard.config file if necessary. These changes are explained on the CC.NET Confluence site.

On my first pass with this, the output was not accounting for the violations I had suppressed in Visual Studio using the SuppressMessage attribute. The issue was that the SuppressMessage attribute is conditional. You need to define the CODE_ANALYSIS conditional compilation symbol in order for the attributes to be present in your built assemblies and therefore be noticed by FxCopCmd.exe.

Finally, if you're using FireFox instead of IE, you'll notice that the XSL presentation of the FxCop results are pretty ugly and hard to interact with. On the CruiseControl .NET Community XSL Transforms page, you'll want to grab fxcop XSLs from the Alternative Style Sheets and Templates Version 2.2, by Michael Luke. Thanks, Michael!

There's another approach, too, which is to call out to MSBuild to do the CodeAnalysis for you. You might achieve better integration with VS.NET that way. Can't speak to it, though, so you're on your own. If you take that path, leave a comment here and let me know how it turns out.

Quoted in Software Development Times

I was interviewed for an article about hiring software developers in November. The interview appeared in the December 15th issue of Software Development Times [PDF 3.7 MB]. Flip to page 6. Here's a brief excerpt from "Advice From the Trenches: Building a Winning Team," by Jennifer DeJong:

Programming expertise and creativity top the list of what these development managers want in new hires. But communication and collaboration skills matter, too. "The days when a programmer can be an anti-social person who works alone all day in a cubicle are over," said Melia. One way to make sure you don't end up with a throwback on your hands is to get the entire team in on the interview. That can put a candidate on the spot, but it also shows firsthand how they interact with others, said Melia, who is currently recruiting a fourth team member. "You see how they act in a meeting."

I sent the link out to my folks, of course. My mom's reply was choice: "I don't understand this article, but I'm very proud of you." She's got it hanging on her fridge. Just like elementary school!

Speaking of recruiting, I'm looking to hire a senior OO developer for a May start. Get in touch if you're interested!

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