8

I have an annoying view problem that I'm trying to debug and no where on the Haml Documentation Haml Docs does it specify how to debug view code. This is very annoying and all I need is to debug a variable. Can someone please help me with this? Thank you.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Dan Rubio
  • 4,709
  • 10
  • 49
  • 106

3 Answers3

9

In Haml, to print a result on the page, you use = sign, so in your case it is:

= @variable.inspect

To write a conditional statement, for instance if else, you would use -:

-if condition
  # logic
-else
  #logic

Note, there is no end.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
0

I found it best to put

`= debug(params)`

in your layouts/application.html.haml

0

I just put debugger as below:

= f.input :hardware_configuration, collection: ['screen', 'screen_and_printer', 'printer_only']
= debugger

and it was there:

6:     = f.input :hardware_configuration, collection: ['screen', 'screen_and_printer', 'printer_only']  
7:     = debugger  
(byebug) n

Here you can check whatever variable is there directly(of course which you have declared and assigned in controller).

Note: I have byebug gem installed.

Mayuresh Srivastava
  • 1,332
  • 17
  • 24