How to debug Rails apps deployed on Stackato
by Eric Promislow

Eric Promislow, August 30, 2011

It's easy to debug Rails apps deployed on Stackato, for both versions 2 and 3 of Rails (and possibly Rails 1, although we haven't tested it).  It just requires adding some temporary code to your application.

First, you may want to download Komodo 7 Alpha and get access to Stackato Beta.

Follow the steps below:

Step 1:

Copy the full rubylib directory from <komodo-install>/lib/support/dbgp into vendor/. Do not preload this directory with a directive in application.rb -- Komodo will load it on demand.

Step 2:

Add the following contents to the file lib/jit_debug.rb

module JitDebug
  def invoke_debugger_if_needed(debugInfo)
    if (defined? ::Debugger) &&

        defined? ::Debugger::DBGP_CommandProcessor
    if debugInfo =~ /^(.*):(\d+)$/
      host = $1
      port = $2
      host = 'localhost'
      port = 9000
    deleteFirst = false
    dbgpParentDir = File::join(

                          'vendor', 'rubylib')
    if ! $:.include?(dbgpParentDir)
      deleteFirst = true
        "remoteport=#{host}:#{port} logfile=stderr"
      require 'rdbgp'
    rescue LoadError
      $:.shift if deleteFirst

  def self.included?(base)
    base.send :helper_method, :invoke_debugger_if_needed

Step 3:

Include the module in the application_controller.rb file:

class ApplicationController < ActionController::Base
  include JitDebug

Step 4:

Add code that will load the debugger on demand to each controller you're considering debugging:

class MyController < ApplicationController
  before_filter :check_debugger
  #... controller methods

  def check_debugger
    return if !(debugInfo = params[:debug])

Now you can debug pages on demand by adding a parameter to the URL that matches the system Komodo is running on. For example, suppose you're running Komodo on a machine with IP address and
Komodo is listening for debug connections on port 9000 (the default). You can then trigger the debugger by modifying the URL by adding a debug parameter:

This might first stop in Rails library code, which usually isn't interesting. Simply set breakpoints in your controller, model, and erb view files, and press Continue to reach one.

Please note:

Once the Ruby debugger has been loaded, it can't be detached. This means your apps will continue to run more slowly. The only way to get back to non-debugger mode is by ending the session (best by pressing the "Stop Debugging" button in Komodo, and restarting the server).

Note that the names "check_debugger", "debug", "JitDebug", etc. must all be changed if they conflict with your Ruby code.

Again, you can try this out on Komodo 7 Alpha and Stackato Beta.

Subscribe to ActiveState Blogs by Email

Share this post:

About the Author: RSS

Eric Promislow is a senior developer who's worked on Komodo since the very beginning. He has a M.Sc. in Computing Science from Queen's University and a B.Sc. in Biophysics from the University of Ontario. Before joining ActiveState, he helped create the OmniMark text-processing language.