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.
What is the equivalent of <% debug @variable %> for Haml?
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
.
Thanks Andrey for distinguishing the difference. Much appreciated. –
Fortress
I found it best to put
`= debug(params)`
in your layouts/application.html.haml
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.
© 2022 - 2024 — McMap. All rights reserved.
= debug @variable
? – Dotard