Undefined session parameters and hashes in before_filter

Does anyone know why using ruby-debuga call to debuggerthe method called before_filterhashing, paramsand sessionare 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 behavior or am I doing something wrong?

+3
source share
2 answers

Try putting bs line after calling the debugger and see what happens.

+3
source

I don’t know why this does not work, but you can go to variables through controller.params and controller.session

0
source

Source: https://habr.com/ru/post/1709373/


All Articles