3

当我在 erb- 模板文件中使用 if 语句时,if 语句被延迟评估,这混淆了 html:

<small>
<% if @applause_count == 1 %>
    The author has been cheered up once!
<% elsif @applause_count > 1%> 
    The author has been cheered up <%=  @applause_count %> times! <br/>Be the next!
<% end if %> 
</small>

产生:

<small>
</small>
The author has been cheered up 100 times! <br/>Be the next!

有人可以向我解释这种奇怪的行为吗?

4

1 回答 1

2

如前所述,问题在于<% end if %>

利用<% end %>

这会产生所需的 html:

<small>
The author has been cheered up 2 times! <br/>Be the next!
</small> 
于 2013-10-31T16:40:41.530 回答