Rails Debug - How to print variable values on every step

2.3k views Asked by At

Say I have a variable called @test_var

And I have hundred lines of code using this variable

On debugging I need to give n for next step and @test_var to check the value

Can I do both in single command (i.e) print the value of a variable on every step ?

3

There are 3 answers

0
deivid On BEST ANSWER

You are looking for

display @test_var

After that, @test_var will be printed every time the debugger stops.

4
Debadatt On

If you want to print it in controller then

for each line give one heading like

p "step 1"
p @test_var

p "step 2"
p @test_var
0
Igor Kasyanchuk On

My own solution to print and debug variables is https://github.com/igorkasyanchuk/wrapped_print

you can simply call @test_var.wp to see in the logs a value of this variable