Debugging Rails Application with Breakpoint Library

Rails application can be debugged with breakpoint library that allows you to top the flow of code execution and examine Ruby session. This examination allows you to expose local variables, modify them, and resume execution of your program. This is much better alternative to logging every step of the way with your log messaging.

In order to start debugging session with Rails you need to set breakpoints first and then start up your Rails server in debug mode via the following command line

> rails server –debbuger

Please note, breakpoints can be set anywhere within Ruby code including models, controllers, and helpers.  When your process hit the breakpoint, the irb session will start up your terminal.

Here is an example how you can set breakpoint in your code.

class Item < ActiveRecord::Base
 attr_accessor :title
 def title = (title)
  super
  breakpoint
 end
end

If your process hit breakpoint, it will stop processing your session and start up terminal with Ruby session running. This session allows you to look at all the local variable and methods. You can pass a name of the method to your breakpoints so you can see very descriptive message when debugging. 

Featured pages

Ruby

Set of Ruby Object Oriented Programming Language tutorials that cover such topics as Ruby strings, …

Rails

Rails Framework tutorial teaches you how to utilize de facto framework of choice for Ruby developme…

Ruby Duck Typing

“If an object quacks like a duck just go ahead and treat it as a duck” – this fun…

Regular Expressions

Ruby uses the =~ operator to check any given string against regular expression. For example, a stri…

Credit Card Number

Every last digit of any credit card is a check sum digit that is determined by all digits in front …

Ruby Arrays

Ruby Programming Language has built in support for Arrays. Arrays help you define some of the compl…

Ruby Hashes

Hashes are very similar to arrays in Ruby and hashes interface is similar to Ruby array interface. …

Ruby Code Block

Ruby is very unique language when it comes to code blocks. You can simply pass a code block to a me…