gpt4 book ai didi

ruby - 如果语句未按顺序呈现,Rails 模板呈现 ERB

转载 作者:数据小太阳 更新时间:2023-10-29 08:04:31 25 4
gpt4 key购买 nike

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

关于ruby - 如果语句未按顺序呈现,Rails 模板呈现 ERB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19710163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com