Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this embedded ruby delimiter? -%>

"-%>" appears in some code in a tutorial I'm doing, as a delimiter of some embedded ruby, like this:

<% 5.times do |i| -%>
    <%= thumbnail_tag slideshow.slides[i] %>
<% end -%>

What does it mean? There's nothing in the book about it (Rails Up and Running)

like image 938
kajaco Avatar asked May 23 '09 16:05

kajaco


People also ask

What is Embedded Ruby interpreter?

eRuby stands for embedded Ruby. It's a tool that embeds fragments of Ruby code in other files such as HTML files similar to ASP, JSP and PHP. eRuby allows Ruby code to be embedded within (delimited by) a pair of <% and %> delimiters.

How Embedded Ruby works?

Embedded Ruby allows ruby code to be embedded in a view document. This code gets replaced with proper value resulted from the execution of the code at run time. But, by having the ability to embed code in a view document, we risk bridging the clear separation present in the MVC frame.

Can Ruby be embedded in HTML?

As we said above, Ruby on Rails allows you to write Ruby inside your HTML content. This is called Embedded Ruby and that's why the files you actually create have the extension . html. erb .

What is an ERB file?

What is a ERB file. ERB files contain source code written in a programming language of the same name. The ERB language is essentially a Ruby templating language. ERB files are saved in a plain text format which allows them to be opened in any text editing program.


2 Answers

The template language ERB supports <%- and -%> in addition to the Ruby code delimiters <% and %>.

Adding a minus to the inner side of the delimiter strips whitespace from the HTML next to the outer side of the delimiter.

like image 104
pts Avatar answered Sep 22 '22 22:09

pts


In ERB it removes any newline that follows from the output.

like image 30
John Topley Avatar answered Sep 23 '22 22:09

John Topley