Created
April 8, 2009 03:42
-
-
Save davidphasson/91613 to your computer and use it in GitHub Desktop.
ERB and the case statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Doesn't work | |
<p> | |
<% case @request.author_hosted %> | |
<% when "yes" %> | |
The school <b>has</b> hosted an author before. | |
<% when "no" %> | |
The school <b>has not</b> hosted an author before. | |
<% end %> | |
</p> | |
# Does | |
<p> | |
<% case @request.author_hosted | |
when "yes" %> | |
The school <b>has</b> hosted an author before. | |
<% when "no" %> | |
The school <b>has not</b> hosted an author before. | |
<% end %> | |
</p> |
Found that adding a line break also works:
Doesn't work
<p>
<% case @request.author_hosted %>
<% when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>
Does
<p>
<% case @request.author_hosted
when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>
Also Does
<p>
<% case @request.author_hosted -%>
<% when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case someone is curious, here is an issue on the ERB repo: ruby/erb#4