Rhtml templates and syntax

Hello,
where do we need <% -%> in templates ? What is the difference between
<%= %> and it ?

<%= %> will execute the contained ruby and inject the result into the
document.

<% %> will execute the contained ruby, but will NOT inject anything
into the document (other than a blank line) … hence …

<% -%> will execute the contained ruby and will not inject anything
into the document (not even a blank line).

-Derrick S.

Derrick S. wrote:

<%= %> will execute the contained ruby and inject the result into the
document.

<% %> will execute the contained ruby, but will NOT inject anything
into the document (other than a blank line) … hence …

<% -%> will execute the contained ruby and will not inject anything
into the document (not even a blank line).

-Derrick S.

Thank You, Derrick!
:slight_smile:

You can also use - with the include. I.e.
<%= “blah” -%>

This will inject “blah” into the output, but will not create a new line.

This is useful when you’re pulling data into something that is
surrounded by quotes (like an HREF) where you don’t want the newlines
and want to maintain readability.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs