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]
[/html]
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!



