erb去掉末尾换行 -%>使用方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了erb去掉末尾换行 -%>使用方法相关的知识,希望对你有一定的参考价值。
http://stackoverflow.com/questions/998979/difference-between-and-in-rails/25617607#25617607
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
以上是关于erb去掉末尾换行 -%>使用方法的主要内容,如果未能解决你的问题,请参考以下文章