Difference between -%> and %> in rails

ruby-on-rails

Solution

The extra dash makes ERB not output the newline after the closing tag. There's no difference in your example, but if you have something like this:

<div>
  <% if true -%>
  Hi
  <% end -%>
</div>

It'll produce:

<div>
  Hi
</div>

and not this:

<div>

  Hi

</div>

Problem

I have started some rails tutorials and noticed that some of the view code blocks are like ``` <h1><%= @subject.name -%></h1> ``` and other code blocks are like ``` <h1><%= @subject.name %></h1> ``` What is the difference between -%> and %> If you know of some good syntax references you can point me to, that would also be helpful.

Original source

Related problems