Whats the difference between "<%= abc %>" and "<%= abc -%>"

What difference does the "-" at the end make?

What difference does the "-" at the end make?

-%> eats the newline.

.<%= abc %><%= xyz %>. will turn into

.abc
xyz
.

.<%= abc -%><%= xyz -%>. will turn into

.abcxyz.

-philip

Thanks Philip, that makes sense.

According to Agile Development with Rails this is not quite correct. The - is supposed to remove the newline after the -%>
So
<%= “abc” %><%= “def” %>

<%= “ghi” %><%= “klm” %>

will provide

abcdef
ghijkl

but
<%= “abc” %><%= “def” -%>

<%= “ghi” %><%= “klm” %>

will provide

abcdefghijkl

However on testing this in Rails 2.2.2 and viewing the source of the page, I am not seeing this. The - seems to make no difference, I see the two line output in both cases.

Can anyone elucidate?

Colin

Ah... the -%> is only "end of line". Didn't realize that.

I just plugged this into 2.2.2:

<%= "abc" %><%= "def" %>
<%= "ghi" %><%= "klm" %>

Chances are your web server supports some sort of output compression,
so all this doesn't really matter much. Surely you don't depend on
newlines to properly display a page, right?

Which is what you should get, I tried exactly the same and got

abcdef
ghiklm

Is the -%> only used with a <%= ?
Can it be used with, for example <% end -%>

Yes it can, in fact that is possibly the main use as it removes the line completely from the source. Also useful with ‘for’ and so on.
Colin