"-%>
" 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)
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.
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.
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 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.
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.
In ERB it removes any newline that follows from the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With