/call_stack1.8.5.rb", 13, #
, :Ruby]]
baz
The first line of that backtrace corresponds to the call_stack_on method. A warning:
since call_stack works by hooking every method call and return, it slows execution
even when the data collected is not being used.
We can use call_stack to our advantage to trace the flow of execution through a
Rails request. After installing the call_stack gem, place these two lines at the end of
environment.rb:
require 'call_stack'
call_stack_on
Then, you can place the following line in an action to log a stack trace with the class
name and function name for each stack frame:
logger.info(call_stack(-1).map{|frame| "#{frame[0]} : #{frame[1]}"} * "\n")
Debugging Ruby and Rails
Ruby ships with a built-in debugger, rdebug. However, Kent Sibilev has improved
upon this and released his own Ruby debugging library, ruby-debug. This is a fullfeatured
Ruby debugger that also includes breakpoint support for Rails.
Rails used to have built-in debugging support, based on Binding.of_
caller, that exploited a Ruby 1.8.4 bug. When the bug was fixed in
Ruby 1.8.5, the breakpointer broke and we had to rely on third-party
utilities to debug Rails applications.
To start using ruby-debug, install it with gem:
$ sudo gem install ruby-debug
When installed, ruby-debug installs an rdebug binary that is called just like the Ruby
executable.
Pages:
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90