Forum: Ruby on Rails rhtml templates and syntax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Marius Å. (Guest)
on 2006-03-20 22:23
Hello,
where do we need <% -%> in templates ? What is the difference between
<%= %> and it ?
Derrick S. (Guest)
on 2006-03-20 22:31
(Received via mailing list)
<%= %> 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.
Marius Å. (Guest)
on 2006-03-20 22:35
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!
:)
Kenneth L. (Guest)
on 2006-03-21 00:18
(Received via mailing list)
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 topic is locked and can not be replied to.