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
2010-09-27 06:33:53
+5
A:
It's delete on Rails 3.
Now with Rails 3, there are no difference between this 2 forms.
shingara
2010-09-27 07:03:49
Not sure where you read that, but -%> still stops ERB from producing a trailing newline in rails 3.
Samuel
2010-09-27 13:24:51
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
2010-09-27 18:35:16
@Tim That means it will remove the trailing CR from your HTML output, not from every line. -%> still exists and is still useful.
Samuel
2010-09-28 18:36:46