I want to write a switch case in my view :
<% @prods.each_with_index do |prod, index|%> <% case index %> <% when 0 %><%= image_tag("#{prod.img}", :id => "one") %> <% when 1 %><%= image_tag("#{prod.img}", :id => "two") %> <% when 2 %><%= image_tag("#{prod.img}", :id => "three") %> <% end %> <% end %>
But it doesn't work. Do I have to add a <% end %>
somewhere in each line ? Any ideas ? Thanks !
You should pull your first when
into same block as case
<% @prods.each_with_index do |prod, index|%> <% case index when 0 %><%= image_tag prod.img, :id => "one") %> <% when 1 %><%= image_tag prod.img, :id => "two") %> <% when 2 %><%= image_tag prod.img, :id => "three") %> <% end %> <% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With