Ruby Rails模板呈现ERB if语句呈现顺序不正确
当我在erb模板文件中使用if语句时,if语句的求值延迟,这将混合html:Ruby Rails模板呈现ERB if语句呈现顺序不正确,ruby,if-statement,ruby-on-rails-4,erb,template-engine,Ruby,If Statement,Ruby On Rails 4,Erb,Template Engine,当我在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/
<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>
作者曾被鼓舞过一次!
1%>
作者多次受到鼓舞
成为下一个!
产生:
<small>
</small>
The author has been cheered up 100 times! <br/>Be the next!
作者已经被鼓舞了100次
成为下一个!
有人能给我解释一下这种奇怪的行为吗?如前所述,问题在于
使用
这将生成所需的html:
<small>
The author has been cheered up 2 times! <br/>Be the next!
</small>
作者已经被鼓舞了两次
成为下一个!
我很惊讶这能起作用,在
上应该有语法错误(应该是
)