Rails 模板呈现 ERB 如果语句呈现顺序不正常



当我在 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!

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

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

使用<% end %>

这将生成所需的 html:

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

最新更新