我不能简单地用ruby erb模板系统循环数组.
下面是我的模板:
<% ['foo', 'bar'].each do |val| -%>
<%= val %>
<% end -%>
下面是命令行和结果
erb test.erb
/usr/share/rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/erb.rb:896:in `eval': test.erb:1: syntax error, unexpected ';' (SyntaxError)
'foo', 'bar'].each do |val| -; _erbout.concat "\n"
^
test.erb:3: syntax error, unexpected ';'
; end -; _erbout.concat "\n"
^
from /usr/share/rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/erb.rb:896:in `result'
from /usr/share/rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/erb.rb:878:in `run'
from /usr/share/rvm/rubies/ruby-2.4.1/bin/erb:149:in `run'
from /usr/share/rvm/rubies/ruby-2.4.1/bin/erb:170:in `<main>'
这个简单的例子有什么问题吗?
免责声明:我是一个Ruby和Erb noob ^^
2条答案
按热度按时间vxbzzdmp1#
你不应该在“%"前面加上“-”。
这个应该能用
3duebb1j2#
您必须将 * 修剪模式 * 设置为
-
:从手册页: