ActiveBlog

Debugging Rails Views in Komodo: It Just Works
by

, May 8, 2007

We recently rewrote the Komodo debugger to sit on top of Kent Sibilev's ruby-debug module, and reaped the expected benefits in speed and thread-robustness. But all along we had only been testing Rails debugging with controller files. I had read...

We recently rewrote the Komodo debugger to sit on top of Kent Sibilev's ruby-debug module, and reaped the expected benefits in speed and thread-robustness. But all along we had only been testing Rails debugging with controller files. I had read Kent's post on debugging RHTML templates and figured if it works with ruby-debug, it should now work with Komodo. So I set a breakpoint at a likely-looking line in list.rhtml of my current app, started the debugger, refreshed the browser once Webrick was loaded, and, as advertised, the debugger actually stopped in the RHTML file. The usual Locals variables show up (with one set to "_erbout", since you're actually running erb at this point). This interactive shell session gives you an idea of what you can see:

=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-05-08 13:03:16] INFO  WEBrick 1.3.1
[2007-05-08 13:03:16] INFO  ruby 1.8.5 (2006-08-25) [i386-mswin32]
[2007-05-08 13:03:16] INFO  WEBrick::HTTPServer#start: pid=3940 port=3000
> _erbout
<h1>Listing movies</h1>

<table>

  <tr>
        <td class="dvdlib_item">
> column
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x67423f8 
@sql_type="varchar(255)", @default=nil, @type=:string, 
@precision=nil, @limit=255, @null=true, @primary=false, 
@scale=nil, @name="title", @original_default=nil>
> movie
#<Movie:0x673fba8 @attributes={"created_on"=>"2007-05-02", 
"title"=>"An inconvenient truth", "id"=>"1"}>

Stepping is a bit quirky, and Kent documents this at the
above link. You're actually debugging ERb Ruby code, but the debugger
shows the corresponding RHTML text, so you don't have to step through
low-level library code. However one line of RHMTL might correspond to
several ERb lines, so a step might not take you to a new line. Kent
also points out that if you're spending too much time debugging views,
you probably need to refactor more code into the controller, and write
more tests. These are the reasons why we weren't jumping through hoops
to make this feature work, but I'm always happy to see something that
works fall out of the wash.

Subscribe to ActiveState Blogs by Email

Share this post:

Comments

2 comments for Debugging Rails Views in Komodo: It Just Works
Permalink

I've been using this for a couple of days, and I have to say it's wonderful. I was one of the people who was waiting around for the debugger to pop up, but worse, when toggling breakpoints off, the wait was even longer. This still happens, but not as long as in the 4.0 release. Looking forwards to great things in 4.1. (Haml/Sass syntax highlighting doesn't seem to work yet in 4.1, unless I'm doing something wrong.)

Permalink

Thanks for the note. Happy to hear you like it.

As for toggling the breakpoints, it's a thread-related issue that only happens with multi-threaded programs. We have plans to fix it, but it's going to entail some messing around Komodo's debugging innards.

As for Haml, we don't ship Haml support with Komodo, but I did post a XPI to the extension forum at http://support.activestate.com/forum-topic/haml-syntax-highlighter-v

I haven't done anything with Sass yet.