Reputation: 460
When I'm using an if-statement in an erb- template file, the if statement is evaluated delayed, which is mixing up the 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>
produces:
<small>
</small>
The author has been cheered up 100 times! <br/>Be the next!
Can someone explain me this strange behaviour?
Upvotes: 3
Views: 7544
Reputation: 2062
As noted, the problem is with the <% end if %>
Use <% end %>
This produces the desired html:
<small>
The author has been cheered up 2 times! <br/>Be the next!
</small>
Upvotes: 2