当我在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!
有人能解释我这种奇怪的行为吗?
答案 0 :(得分:2)
如上所述,问题在于<% end if %>
使用<% end %>
这会产生所需的html:
<small>
The author has been cheered up 2 times! <br/>Be the next!
</small>