What is the equivalent of <% debug @variable %> for Haml?
Asked Answered
F

3

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.

Fortress answered 21/1, 2015 at 16:59 Comment(2)
have you tried = debug @variable?Dotard
I knew it had to be simple! I kept trying - debug @variable. Thanks...... I feel sheepish now.Fortress
R
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.

Rhetoric answered 21/1, 2015 at 17:15 Comment(1)
Thanks Andrey for distinguishing the difference. Much appreciated.Fortress
A
0

I found it best to put

`= debug(params)`

in your layouts/application.html.haml

Abe answered 3/7, 2019 at 15:34 Comment(0)
V
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.

Valor answered 21/4, 2021 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.