views:

305

answers:

2

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?

A: 

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

zaius
+1  A: 

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

jshen
A b.s. line..? I'm afraid I don't understand..
andi
a numeric literal like 1 or something like that. b.s. as in bullshit.
jshen
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
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