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

**URL:** <https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248>\
**Category:** Rails\
**Created:** [March 18, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248 "2009-03-18T17:13:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/1 "2009-03-18T17:13:15Z")

</div>

What difference does the “-” at the end make?

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 5:28pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/2 "2009-03-18T17:28:34Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 6:27pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/3 "2009-03-18T18:27:18Z")

</div>

Thanks Philip, that makes sense.

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 10:31pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/4 "2009-03-18T22:31:17Z")

</div>

> > xyz  
> > So  
> > \<%= “ghi” %\>\<%= “klm” %\>
> 
> Can anyone elucidate?

Ah… the -%\> is only “end of line”. Didn’t realize that.

I just plugged this into 2.2.2:

\<%= “abc” %\>\<%= “def” %\>  
\<%= “ghi” %\>\<%= “klm” %\>

* * *

\<%= “abc” %\>\<%= “def” -%\>  
\<%= “ghi” %\>\<%= “klm” %\>

And got back this:

abcdef  
ghiklm

* * *

abcdefghiklm

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 10:31pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/5 "2009-03-18T22:31:52Z")

</div>

On Wed, Mar 18, 2009 at 4:00 PM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > .
> 
> 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

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?

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 10:46pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/6 "2009-03-18T22:46:32Z")

</div>

2009/3/18 Philip H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> * * *
> 
> abcdefghiklm

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

abcdef  
ghiklm

* * *

abcdef  
ghiklm

Which is not correct. Following a little head scratching I realised  
that  
that the erb file had windows line endings (\r\n) but I am now working  
on  
Ubuntu. I changed the line endings to Unix format and I got  
abcdefghiklm in  
the second case as expected.

Is this a reportable bug? should the -%\> not remove \r\n if present?  
Colin

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 19, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/7 "2009-03-19T18:39:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 18, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/8 "2009-03-18T22:01:54Z")

</div>

2009/3/18 Philip H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

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

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

---

<div class="post-metadata">

**Author:** ![sultan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@sultan](https://www.ruby-forum.com/u/sultan)\
**Post date:** [March 19, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/whats-the-difference-between-abc-and-abc/163248/9 "2009-03-19T19:19:43Z")

</div>

2009/3/19 sultan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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
