What are the minus signs for in the if statement? Cannot seem to find
anything about this, and searching on “-” in this context is hard to get
anything meaningfull back.
The minus sign means that the code will take no space on the page if
the IF does not fire. I think they call it "supressing the newline
that follows the %> delimiter.
The “-%>” causes ERb to suppress the newline on any output. If you have
output, it will not have an ending newline, if you have no output, you
will not get meaningless blank lines.
The ERb documentation says you can suppress newlines with the trim_mode
setting, but does not say what the default trim_mode character is.
-Sean
Mark H. wrote:
I seen some RoR code that went like this:
<% if …blah, blah… -%>
… blah, blah
<% end -%>
What are the minus signs for in the if statement? Cannot seem to find
anything about this, and searching on “-” in this context is hard to get
anything meaningfull back.
This notation is typically used on embedded Ruby (ERb) lines that
produce no output (if, end, etc.) so that no extraneous blank lines
are produced in the HTML.