Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minus Percent Greater-Than vs Percent Greater-Than (i.e. -%> vs %>)

I'm new to Ruby on Rails and am working my way through the tutorial posted here: http://www.tutorialspoint.com/ruby-on-rails/index.htm

One of the questions I have is that I see this used sparingly throughout the code samples:

<%= link_to c.title, {:action => 'show', :id => c.id} -%>

Where other times, I see this:

<%= link_to 'Edit', {:action => 'edit', :id => c.id} %>

Specifically, I'm wondering if there is a reason for that minus sign (-) before the closing %> or if its just a typo on behalf of the author.

On a side note, I've tried searching google and SO for similar questions, but -%> isn't exactly a google friendly search term.

like image 902
jerhinesmith Avatar asked May 26 '09 18:05

jerhinesmith


1 Answers

A dash either immediately after the opening tag (<%-) or immediately before the closing tag (-%>) trims all whitespace before or after the tag, respectively. The most common use, such as you reference above, is to use -%> to avoid inserting a newline after the code.

like image 63
Pesto Avatar answered Nov 06 '22 23:11

Pesto