I'm a noob at this and can't figure out why the hyphen gets added to something like this:
<% if flash[:notice] -%> <%= flash[:notice] %> <% end -%>
Not even sure if my jargon in the title of this question is accurate.
I'm a noob at this and can't figure out why the hyphen gets added to something like this:
<% if flash[:notice] -%> <%= flash[:notice] %> <% end -%>
Not even sure if my jargon in the title of this question is accurate.
The hyphen is not necessary in the above code. Simply adding <% end %> is sufficient to execute the embedded ruby.
The use of hyphen is fully explained here and essentially effects rendered html. In your case, what the hyphen does is this:
1 Hyphen at the end of the tag, just the two spaces
2 before the tag on the line below will be left
3 <% -%>
4 Last line
The code will output with two spaces before " Last Line" just below your <% -%> tag
It means that it will add the \n (or maybe \r\n, I forget which) to the line. It just effects way the HTML is formatted.
So if did:
>> helper.image_tag "image.jpg"
=> "<img alt=\"Image\" src=\"/images/image.jpg\" />"
it would output something like:
"<img alt=\"Image\" src=\"/images/image.jpg\" />\r\n"
Meaning that your html page would look like:
<image tag>
<whatever other tag>
instead of having them both on the same line.
It means simply:
Place any text (HTML) that follows <% -%> on the next line in the rendered template.