I’m printing a list from an array object and when it’s done going through all the items in the array, it prints the word “true” in the HTML.
The code looks like this:
%ul
= for i in users
%li
= i.username
This prints:
username1
username2
username3
true
which looks like this in the html output:
<ul>
<li>username1</li>
<li>username2</li>
<li>username3</li>
true
</ul>
Why is that true getting printed and how do I get rid of it?
Your problem is that you are using
=for the loop, which causes the result of the expression to be output. When you want to run Ruby code but not have the value emitted into the output, use-instead:This can be written more simply as:
Proof:
As an aside, I personally find this usage of
forin Ruby abhorrent. Instead I personally recommend: