3

Does anybody know why, when using ruby-debug by calling debugger in a method called as a before_filter, the params and session hashes are not defined?

class MyExampleController < ActionController::Base

  before_filter :test_hashes

  def test_hashes
    pp session    
    pp params   #both work as expected..

    debugger #calling the debug console
  end

  def index
    #whatever..
  end

end

#the rdb console
(rdb:5) pp params
NameError Exception: undefined local variable or method 'params' for #<ActionController::Filters::BeforeFilter:0x3eafda0>
(rdb:5) pp session
NameError Exception: undefined local variable or method 'session' for #<ActionController::Filters::BeforeFilter:0x3eafda0>

Is this normal behaviour or am I doing something wrong?

andi
  • 14,322
  • 9
  • 47
  • 46

2 Answers2

3

Try putting a b.s. line after the call to debugger and see what happens.

jshen
  • 11,507
  • 7
  • 37
  • 59
  • a numeric literal like 1 or something like that. b.s. as in bullshit. – jshen May 30 '09 at 23:08
  • I thought you were referring to that BS, but I couldn't see how could that do any good. :) But I did try it and it worked! I can't believe it! How come?! Do you have a reasonable explanation? Is this a bug? – andi Jun 01 '09 at 07:18
  • It seems to break on the line after 'debugger'. When you put 'debugger' at the end of a method it breaks somewhere up the call stack. – jshen Jun 01 '09 at 16:13
0

No idea why it doesn't work, but you can get to the variables through controller.params and controller.session

zaius
  • 6,409
  • 4
  • 28
  • 50