UPDATE: This answer was wrong, see https://stackoverflow.com/a/25626629/895245 instead.
In Ruby 2.1 (not necessarily with Rails), the -
removes one trailing newline:
- the newline must be the first char after the
>
- no spaces are removed
- only a single newline is removed
- you must pass the
'-'
option to use it
Examples:
require 'erb'
ERB.new("<%= 'a' %>\nb").result == "a\nb" or raise
begin ERB.new("<%= 'a' -%>\nb").result; rescue SyntaxError ; else raise; end
ERB.new("<%= 'a' %>\nb" , nil, '-').result == "a\nb" or raise
ERB.new("<%= 'a' -%>\nb" , nil, '-').result == 'ab' or raise
ERB.new("<%= 'a' -%> \nb" , nil, '-').result == "a \nb" or raise
ERB.new("<%= 'a' -%>\n b" , nil, '-').result == 'a b' or raise
ERB.new("<%= 'a' -%>\n\nb", nil, '-').result == "a\nb" or raise
Doc: http://ruby-doc.org/stdlib-2.1.1/libdoc/erb/rdoc/ERB.html
Rails 4.1 documents this at http://api.rubyonrails.org/classes/ActionView/Base.html, and appears to:
use ERB by default at: https://github.com/rails/rails/blob/fcbdac7e82725c388bf5adf56a9a9a16d4efdbe0/actionview/lib/action_view/template/handlers.rb#L10
set -
by default at: https://github.com/rails/rails/blob/fcbdac7e82725c388bf5adf56a9a9a16d4efdbe0/actionview/lib/action_view/template/handlers/erb.rb#L77
However, Rails 4.1 does remove trailing whitespaces as documented while pure ERB does not, so there may be other differences.
Also, it is not removing the leading newlines as documented: it might be a documentation bug. Opened an issue at: https://github.com/rails/rails/issues/16766