'-%>' (minus sign) at the end of the ERb sequence

What is the use of a β€œ-” sign (minus sign) at the end of an ERb sequence?

Example:

<% 3.times do -%> FooBar<br /> <% end -%> Sometext 

Regardless of whether I use '-' or not, the browser displays the same result.

Thanks, Aplha.

+49
ruby ruby-on-rails
Dec 10 '10 at
source share
2 answers

Before Rails 3, ERB adds extra spaces before and after the value when rendering HTML content. HTML spaces are not significant except when you use custom tags such as <pre> .

Use of a character - forces the ERB to avoid extra spaces.

This is completely useless in Rails 3.

+68
Dec 10 '10 at
source share

Using the minus sign on the opening or closing part of the erb label suppresses spaces before or after the tag in this line.

This was mostly useful when creating things like text / regular emails with erb, but as @Simone noted, he is now discussing.

+4
Dec 10 '10 at
source share



All Articles