Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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>
@moeabdol

This comment has been minimized.

Copy link

moeabdol commented Apr 16, 2015

Thanks...this solved my problem...weird though!

@passalini

This comment has been minimized.

Copy link

passalini commented Jan 12, 2016

Thanks!

@afirth

This comment has been minimized.

Copy link

afirth commented Mar 23, 2016

I hope I never have to look at this again. Thanks for saving me a few headbangs.

@pabelnl

This comment has been minimized.

Copy link

pabelnl commented Sep 1, 2016

Thanks man, really helped me

@ZempTime

This comment has been minimized.

Copy link

ZempTime commented Nov 4, 2016

Eight years later, this is still relevant. Thanks!

@barrettclark

This comment has been minimized.

Copy link

barrettclark commented Nov 14, 2016

Thank you 🚀

@luckymike

This comment has been minimized.

Copy link

luckymike commented Nov 21, 2016

LOL, just used this tip last week.

@hoffmanilya

This comment has been minimized.

Copy link

hoffmanilya commented Mar 3, 2017

Thanks!

@y-chiasson

This comment has been minimized.

Copy link

y-chiasson commented Aug 16, 2017

wow

@adis-io

This comment has been minimized.

Copy link

adis-io commented Oct 4, 2017

Ruby 2.3.1 ERB works without this hack ;) Didn't tested on previous versions

@Victoriosu

This comment has been minimized.

Copy link

Victoriosu commented Nov 20, 2017

Thanks a lot!

@philihp

This comment has been minimized.

Copy link

philihp commented Jun 15, 2018

Thanks!

@ravicious

This comment has been minimized.

Copy link

ravicious commented Sep 17, 2018

@adis-io Hmm, I still had to use the workaround for Ruby 2.3.3:

$ rails c
Running via Spring preloader in process 90217
Loading development environment (Rails 5.1.2)
>> ERB.version
=> "erb.rb [2.1.0 2015-12-20]"

$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin17]

Edit: Turns out the vim plugin which runs linters on files must have been using the old (system) version of Ruby, as it indeed works without the hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.