# Stripping whitespace in generated output

**URL:** <https://www.ruby-forum.com/t/stripping-whitespace-in-generated-output/116749>\
**Category:** Rails\
**Created:** [October 9, 2007, 10:41am UTC](https://www.ruby-forum.com/t/stripping-whitespace-in-generated-output/116749 "2007-10-09T10:41:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [October 9, 2007, 10:41am UTC](https://www.ruby-forum.com/t/stripping-whitespace-in-generated-output/116749/1 "2007-10-09T10:41:16Z")

</div>

When viewing the generated HTML, I notice a lot of whitespace. Is  
there a simple way to hook into the output just before it is sent to  
the client so I can replace multiple spaces with one space?

Or, if possible, any way to teach erb to only output one space for  
every whitespace region?

–Michael

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [October 9, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/stripping-whitespace-in-generated-output/116749/2 "2007-10-09T14:27:59Z")

</div>

On Oct 9, 2007, at 3:40 , Michael G. wrote:

> Or, if possible, any way to teach erb to only output one space for  
> every whitespace region?

Use \<%- and -%\> (note the additional - characters) instead of \<% and  
%\> to eat up whitespace.

Michael G.  
grzm seespotcode net
