views:

38

answers:

1

Is there a way like how we debug models / controllers with logger.debug? Or even a better method?

Thank you!

Edit 1

Using ruby-debug seems like a steep learning curve for me, could anyone point me something similar to logger.debug, perhaps?

Edit 2

Alright, I think I started to get a grasp on ruby-debug.

Some useful notes for newbies to setup & use ruby-debug:

gem install ruby-debug
in config/environments/development.rb add

include 'ruby-debug'

then just above the code you want to debug add:

debugger

if you need to debug third party plugin / gem, use

include 'ruby-debug'
debugger

just use ruby script/server to run, no need to add --debugger

Edit 3

This plugin really helps me out in understanding the flow of Rails application. I highly recommend this to any newbies going pro!

Simply setup ruby-debug, then put debugger code anywhere in your controller under the action your application requested. You will then find great revelation!

+1  A: 

I highly recommend you learn to use ruby-debug. You can install it by doing:

gem install ruby-debug

You can then add a debugger statement to your code either in the plugin code or where your code calls the plugin, step through it, and see what's going wrong.

I also personally use these settings which makes it a bit easier to use - put them in a ~/.rdebugrc file.

set autoeval
set autolist
set autoreload
wuputah
I tried using it for a set of test script inside the plugin (by running ctrl + R in Textmate), it returned NoMethodError: undefined method `logger' for true:TrueClass what should I do now?
jaycode
You can't use `Cmd+R` from Textmate with `rdebug` - using the debugger is interactive, so you need an interactive prompt. Run your test script in Terminal with the `rdebug` command. You can also run it with plain ruby if you `require 'ruby-debug'` (rubygems will also need to be loaded for that to work).
wuputah
Here's a screencast which covers using ruby-debug in a Rails app: http://railscasts.com/episodes/54-debugging-with-ruby-debug
wuputah