Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Forked from BBonifield/gist:608257
Created October 3, 2010 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/608991 to your computer and use it in GitHub Desktop.
Save JoshCheek/608991 to your computer and use it in GitHub Desktop.
<!-- It is probably easier to read if you initialize item_images to be an empty hash -->
<% @item.item_images ||= Hash.new %>
<% @item.item_images.each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
<% end %>
<!-- Or return a default value for when it is nil -->
<% (@item.item_images || Hash.new).each do |key, image| %>
<img src="<%= image.path %>" width="397" <% if key != 0 %>style="display:none"<% end %> />
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment