views:

99

answers:

2

I've always used <%= some_code %> to insert Ruby into HTML when using Ruby on Rails. I've just noticed that other projects sometimes use <%= some_code -%>. What is the difference? Thanks for reading.

+8  A: 

<%= some_code -%> The minus at the end removes the newline. Useful for formatting the generated HTML, while <%= some_code %> does not.

Thanks, Anubhaw

Anubhaw
+5  A: 

It's delete on Rails 3.

Now with Rails 3, there are no difference between this 2 forms.

shingara
Not sure where you read that, but -%> still stops ERB from producing a trailing newline in rails 3.
Samuel
According to the Rails 3 release notes: "You no longer need to place a minus sign at the end of a ruby interpolation inside an ERb template to remove the trailing carriage return in the HTML output."
Tim
@Tim That means it will remove the trailing CR from your HTML output, not from every line. -%> still exists and is still useful.
Samuel