Skip to content

Instantly share code, notes, and snippets.

@davidphasson
Created April 8, 2009 03:42
Show Gist options
  • Save davidphasson/91613 to your computer and use it in GitHub Desktop.
Save davidphasson/91613 to your computer and use it in GitHub Desktop.
ERB and the case statement
# 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>
@sandstrom
Copy link

In case someone is curious, here is an issue on the ERB repo: ruby/erb#4

@richjdsmith
Copy link

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